Skip to content

Instantly share code, notes, and snippets.

@Raincode
Created August 4, 2015 19:24
Show Gist options
  • Save Raincode/39b5f006a88e46451042 to your computer and use it in GitHub Desktop.
Save Raincode/39b5f006a88e46451042 to your computer and use it in GitHub Desktop.
function unite(arr1, arr2, arr3) {
var unique = arr1.concat(arr2, arr3);
console.log("arr:");
console.log(unique);
for (var i = 0; i != unique.length; ++i) {
unique.reduce(function(isDuplicate, item, index, arr) {
if (index != i && unique[i] === item) {
delete unique[index];
}
}, 0);
}
var result = [];
for (var key in unique)
if (Boolean(unique[key]))
result.push(unique[key]);
return result;
}
unite([1, 2, 3], [5, 2, 1, 4], [2, 1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment