mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
lodash: Optimize intersection. [jddalton]
Former-commit-id: f15eb7429ab4f14a4b096f5ba72f3662f9ed23d7
This commit is contained in:
20
lodash.js
20
lodash.js
@@ -1101,12 +1101,20 @@
|
|||||||
* // => [1, 2]
|
* // => [1, 2]
|
||||||
*/
|
*/
|
||||||
function intersection(array) {
|
function intersection(array) {
|
||||||
var rest = slice.call(arguments, 1);
|
var value,
|
||||||
return filter(uniq(array), function(value) {
|
index = -1,
|
||||||
return every(rest, function(other) {
|
length = array.length,
|
||||||
return indexOf(other, value) > -1;
|
others = slice.call(arguments, 1),
|
||||||
});
|
result = [];
|
||||||
});
|
|
||||||
|
while (++index < length) {
|
||||||
|
value = array[index];
|
||||||
|
if (indexOf(result, value) < 0 &&
|
||||||
|
every(others, function(other) { return indexOf(other, value) > -1; })) {
|
||||||
|
result.push(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user