Last active
August 29, 2015 14:24
-
-
Save Kasahs/db11429e2d65e1fc9b4f to your computer and use it in GitHub Desktop.
Efficient pure Javascript array union
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
var array1 = [1,2,3,4,5]; | |
var array2 = [1,2,3,4,5,6,7,8,9,10]; | |
var union = []; | |
set = {}; | |
for(var j = 0; j < array1.length; j++){ | |
set[array1[j]] = true; | |
} | |
for(var k = 0; k < array2.length; k++){ | |
set[array2[k]] = true; | |
} | |
for (var item in set){ | |
union.push(item); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment