Last active
August 29, 2015 14:20
-
-
Save gr0uch/e7f7146735d7aec2f795 to your computer and use it in GitHub Desktop.
Get the union of arrays by means of the Set type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the union of arrays with unique values by means of the Set type. | |
* | |
* @param {Array[]} | |
* @return {Set} | |
*/ | |
function union () { | |
return new Set(arguments[0].concat( | |
...Array.prototype.slice.call(arguments, 1))) | |
} | |
console.log(union([1, 2, 3], [2, 3, 4])) // => [1, 2, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment