chg: refactored and simplified Array.union() method
This commit is contained in:
parent
aa2a236d91
commit
0b938bf808
1 changed files with 3 additions and 12 deletions
|
@ -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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue