Skip to content

Instantly share code, notes, and snippets.

@platypusrex
Last active October 15, 2015 04:27
Show Gist options
  • Save platypusrex/6add635112804a82cf43 to your computer and use it in GitHub Desktop.
Save platypusrex/6add635112804a82cf43 to your computer and use it in GitHub Desktop.
Javascript - Take 2 or more arrays and return an array of unique value in the original order
function unite(arr1, arr2, arr3) {
return Array.from(arguments).reduce(function(a, b){
return a.concat(b).filter(function(val,pos,arr){
return arr.indexOf(val) === pos;
});
});
}
unite([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment