Last active
December 15, 2015 17:00
-
-
Save Dammmien/28db582fe3b54b62202b to your computer and use it in GitHub Desktop.
Concatenate two arrays and remove duplicate
This file contains hidden or 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
// if no duplicate in the first list | |
a1.concat( a2.filter( i => a1.indexOf( i ) === -1 ) ); | |
// if duplicate in the first list | |
a1.concat( a2 ).reduce( function( p, c, i, a ) { | |
if ( p.indexOf( c ) === -1 ) p.push( c ); | |
return p; | |
}, [] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment