Skip to content

Instantly share code, notes, and snippets.

@jepras
Created October 1, 2018 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jepras/673ed3ce234b139b6883fd2711b80289 to your computer and use it in GitHub Desktop.
Save jepras/673ed3ce234b139b6883fd2711b80289 to your computer and use it in GitHub Desktop.
Using flat() to flatten from multiple arrays into 1. Using Set on flat array to only get unique values.
function uniteUnique(arr) {
var newArray = [];
for (let array of arguments) {
newArray.push(array);
}
var flatArray = newArray.flat()
var unique = [...new Set(flatArray)];
return unique;
}
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment