chg: refactored and simplified Array.intersection() method
This commit is contained in:
parent
0b938bf808
commit
f6656f7b4d
1 changed files with 3 additions and 15 deletions
|
@ -51,21 +51,9 @@ Array.union = function() {
|
|||
* @return {Array} the intersection set
|
||||
*/
|
||||
Array.intersection = function() {
|
||||
var all = Array.union.apply(this, arguments);
|
||||
var result = [];
|
||||
for (var n in all) {
|
||||
var chksum = 0;
|
||||
var item = all[n];
|
||||
for (var i=0; i<arguments.length; i+=1) {
|
||||
if (arguments[i].contains(item))
|
||||
chksum += 1;
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (chksum == arguments.length)
|
||||
result.push(item);
|
||||
}
|
||||
return result;
|
||||
return Array.from(arguments).reduce((result, array) => {
|
||||
return result.filter(element => array.includes(element));
|
||||
});
|
||||
};
|
||||
|
||||
// prevent any newly added properties from being enumerated
|
||||
|
|
Loading…
Add table
Reference in a new issue