Skip to content

Instantly share code, notes, and snippets.

@Dammmien
Last active December 15, 2015 17:00
Show Gist options
  • Save Dammmien/28db582fe3b54b62202b to your computer and use it in GitHub Desktop.
Save Dammmien/28db582fe3b54b62202b to your computer and use it in GitHub Desktop.
Concatenate two arrays and remove duplicate
// 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