Some formatting

pull/2/head
Louis Chatriot 11 years ago
parent 9a917a6d57
commit 34d456dd29
  1. 9
      lib/cursor.js
  2. 16
      test/cursor.test.js

@ -84,16 +84,17 @@ Cursor.prototype._exec = function(callback) {
if (this._sort) { if (this._sort) {
keys = Object.keys(this._sort); keys = Object.keys(this._sort);
// Going backwards so that the first sort is the last that gets applied // Sorting
var criteria = []; var criteria = [];
for (i = 0; i < keys.length; i++) { for (i = 0; i < keys.length; i++) {
key = keys[i]; key = keys[i];
criteria.push({ key: key, direction: self._sort[key] }); criteria.push({ key: key, direction: self._sort[key] });
} }
res.sort(function(a, b) { res.sort(function(a, b) {
for (var i = 0; i < criteria.length; i++) { var criterion, compare, i;
var criterion = criteria[i]; for (i = 0; i < criteria.length; i++) {
var compare = criterion.direction * model.compareThings(model.getDotValue(a, criterion.key), model.getDotValue(b, criterion.key)); criterion = criteria[i];
compare = criterion.direction * model.compareThings(model.getDotValue(a, criterion.key), model.getDotValue(b, criterion.key));
if (compare !== 0) { if (compare !== 0) {
return compare; return compare;
} }

@ -606,16 +606,19 @@ describe('Cursor', function () {
], done); }); ], done); });
it('Similar data, multiple consecutive sorts', function(done) { it('Similar data, multiple consecutive sorts', function(done) {
var i, j, id
, companies = [ 'acme', 'milkman', 'zoinks' ]
, entities = []
;
async.waterfall([ async.waterfall([
function (cb) { function (cb) {
d.remove({}, { multi: true }, function (err) { d.remove({}, { multi: true }, function (err) {
if (err) { return cb(err); } if (err) { return cb(err); }
var entities = []; id = 1;
var companies = [ 'acme', 'milkman', 'zoinks' ]; for (i = 0; i < companies.length; i++) {
var id = 1; for (j = 5; j <= 100; j += 5) {
for (var i = 0; i < companies.length; i++) {
for (var j = 5; j <= 100; j += 5) {
entities.push({ entities.push({
company: companies[i], company: companies[i],
cost: j, cost: j,
@ -632,7 +635,6 @@ describe('Cursor', function () {
}, function(err) { }, function(err) {
return cb(); return cb();
}); });
}); });
} }
, function (cb) { , function (cb) {

Loading…
Cancel
Save