Created
August 31, 2018 22:02
-
-
Save juanbrusco/a18dee7c8015e6d3fa861ee31eaf9736 to your computer and use it in GitHub Desktop.
Merge 2 arrays - Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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