chg: refactored and simplified Array.union() method

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

View file

@ -38,18 +38,9 @@ Array.prototype.contains = Array.prototype.includes
* @return {Array} the union set * @return {Array} the union set
*/ */
Array.union = function() { Array.union = function() {
var result = []; return Array.from(arguments).reduce((result, array) => {
var map = {}; return result.concat(array.filter(element => !result.includes(element)));
for (var i=0; i<arguments.length; i+=1) { }, []);
for (var n in arguments[i]) {
var item = arguments[i][n];
if (!map[item]) {
result.push(item);
map[item] = true;
}
}
}
return result;
}; };
/** /**