chg: refactored and simplified Array.intersection() method

This commit is contained in:
Tobi Schäfer 2020-03-21 13:13:48 +01:00
parent 0b938bf808
commit f6656f7b4d

View file

@ -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