Some formatting

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

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

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

Loading…
Cancel
Save