Skip to content

Instantly share code, notes, and snippets.

@juanbrusco
Created August 31, 2018 22:02
Show Gist options
  • Save juanbrusco/a18dee7c8015e6d3fa861ee31eaf9736 to your computer and use it in GitHub Desktop.
Save juanbrusco/a18dee7c8015e6d3fa861ee31eaf9736 to your computer and use it in GitHub Desktop.
Merge 2 arrays - Javascript
merge_array(array1, array2) {
const result_array = [];
const arr = array1.concat(array2);
let len = arr.length;
const assoc = {};
while (len--) {
const item = arr[len];
if (!assoc[item]) {
result_array.unshift(item);
assoc[item] = true;
}
}
return result_array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment