Skip to content

Commit

Permalink
more tests and a better flattening method for multiArgs
Browse files Browse the repository at this point in the history
Former-commit-id: 6070d90812792f886103bbbe4b432547ecd446fd [formerly ee5695e24a4722774553901afedfc2ec18699394]
Former-commit-id: a3c8df955ad3ce87fbc3ca0f87f59f6918bc82c7
  • Loading branch information
andrewplummer committed Mar 15, 2012
1 parent ead66a2 commit 2f96458
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 42 deletions.
10 changes: 5 additions & 5 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@

function multiArgs(args, fn, flatten, index) {
args = getArgs(args);
if(flatten !== false) args = arrayFlatten(args);
if(flatten === true) args = arrayFlatten(args, 1);
arrayEach(args, fn || function(){}, index);
return args;
}
Expand Down Expand Up @@ -1258,7 +1258,7 @@
i++;
}
}
}, false);
});
return arr;
},

Expand Down Expand Up @@ -1380,7 +1380,7 @@
var arr = this;
multiArgs(arguments, function(a) {
arr = arr.concat(a);
}, false);
});
return arrayUnique(arr);
},

Expand All @@ -1395,7 +1395,7 @@
*
***/
'intersect': function() {
return arrayIntersect(this, multiArgs(arguments), false);
return arrayIntersect(this, multiArgs(arguments, null, true), false);
},

/***
Expand All @@ -1410,7 +1410,7 @@
*
***/
'subtract': function(a) {
return arrayIntersect(this, multiArgs(arguments), true);
return arrayIntersect(this, multiArgs(arguments, null, true), true);
},

/***
Expand Down
49 changes: 12 additions & 37 deletions unit_tests/environments/sugar/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,6 @@ test('Array', function () {



/*
function getRandomizedArray(size) {
var a = [];
for (var i=0; i<size; i++) {
var r1 = Number.random(0,8);
var rand = Number.random(0,size/2)
if (r1==7) {
a[i] = hex_md5(String(rand));
} else if (r1==2) {
a[i] = new RegExp(rand,"g");
} else if (r1==3) {
a[i] = {};
a[i][hex_md5(String(rand))] = rand;
} else if (r1==4) {
a[i] = eval("(function(a){var x='"+rand+"';})");
} else if (r1==5) {
a[i] = [rand,hex_md5(String(rand))];
} else {
a[i] = rand;
}
}
return a;
}
var a = getRandomizedArray(16);
var b = getRandomizedArray(16);
console.info(a);
console.info(b);
console.info(a.union(b));
return;
*/

/*
a = [
Expand Down Expand Up @@ -2381,5 +2344,17 @@ test('Array', function () {
equal(arr1.intersect(arr2), intersectExpected, 'Array#union | complex array intersects');


equal([function(){ return 'a' }].intersect([function() { return 'a'; }, function() { return 'b'; }]), [], 'Array#intersect | functions are always unique');
equal([xFunc].intersect([xFunc, yFunc]), [xFunc], 'Array#intersect | function references are ===');

equal([function(){ return 'a' }, function() { return 'b'; }].subtract([function() { return 'a'; }]).length, 2, 'Array#subtract | functions are always unique');
equal([xFunc, yFunc].subtract([xFunc]), [yFunc], 'Array#subtract | function references are ===');


equal([['a',1]].intersect([['a',1],['b',2]]), [['a',1]], 'Array#intersect | nested arrays are not flattened');
equal([['a',1],['b',2]].subtract([['a',1]]), [['b',2]], 'Array#subtract | nested arrays are not flattened');



});

0 comments on commit 2f96458

Please sign in to comment.