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
|
* @return {Array} the intersection set
|
||||||
*/
|
*/
|
||||||
Array.intersection = function() {
|
Array.intersection = function() {
|
||||||
var all = Array.union.apply(this, arguments);
|
return Array.from(arguments).reduce((result, array) => {
|
||||||
var result = [];
|
return result.filter(element => array.includes(element));
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// prevent any newly added properties from being enumerated
|
// prevent any newly added properties from being enumerated
|
||||||
|
|
Loading…
Add table
Reference in a new issue