Skip to content

Instantly share code, notes, and snippets.

@gr0uch
Last active August 29, 2015 14:20
Show Gist options
  • Save gr0uch/e7f7146735d7aec2f795 to your computer and use it in GitHub Desktop.
Save gr0uch/e7f7146735d7aec2f795 to your computer and use it in GitHub Desktop.
Get the union of arrays by means of the Set type.
/**
* 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