Skip to content

Commit

Permalink
Fixed intersection problem
Browse files Browse the repository at this point in the history
  • Loading branch information
maritz committed Nov 12, 2010
1 parent 2cfdbbf commit 0abac96
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/helpers.js
Expand Up @@ -9,6 +9,12 @@ exports.intersections = function intersections(arrs,cmp) {
lowest,highest,
index,
cur;
if (!arrs.every(function (arr) {
return Array.isArray(arr) && arr.length > 0;
})) {
// one of the arrays is either not an array or empty.
return [];
}
//Copy each array and sort it
arrs=arrs.map(function(a) { return a.slice(0).sort(cmp); });
while (arrs.every(function(x,i) { return x.length>offsets[i]; })) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "nohm",
"version": "0.1.6admin-conductorfix",
"version": "0.1.7admin",
"engines": {
"node" : ">=0.3.0"
},
Expand Down
51 changes: 51 additions & 0 deletions test/find.js
Expand Up @@ -345,4 +345,55 @@ exports.findSameNumericTwice = function (t) {
});
});
});
};

exports.findByMixedIndexMissing = function (t) {
var user = new UserFindMockup(),
user2 = new UserFindMockup(),
user3 = new UserFindMockup(),
findUser = new UserFindMockup();
t.expect(1);

user2.p({
name: 'mixedindextestMissing',
email: 'mixedindextestMissing@hurgel.de',
number: 4
});

user3.p({
name: 'mixedindextestMissing2',
email: 'mixedindextestMissing2@hurgel.de',
number: 4
});

user.save(function (err) {
if (err) {
console.dir(err);
t.done();
}
user2.save(function (err) {
if (err) {
console.dir(err);
t.done();
}
user3.save(function (err) {
if (err) {
console.dir(err);
t.done();
}
findUser.find({
number: {
min: 2
},
name: 'mixedindextASDASDestMISSING'
}, function (err, ids) {
if (err) {
console.dir(err);
}
t.same(ids, [], 'Ids were found even though the name should not be findable.');
t.done();
});
});
});
});
};

0 comments on commit 0abac96

Please sign in to comment.