Skip to content

Instantly share code, notes, and snippets.

@Cycymomo
Last active December 16, 2015 12:19
Show Gist options
  • Save Cycymomo/5434095 to your computer and use it in GitHub Desktop.
Save Cycymomo/5434095 to your computer and use it in GitHub Desktop.
Comparaison de tableaux JS
/*
* L'array le plus long doit être dans tab1
*/
Array.prototype.diff = function diff( tab1, tab2 ){
var tab3 = [];
if (Array.isArray( tab1 ) && Array.isArray( tab2 )){
tab3 = tab1.filter( function( value, index ){
return this[ index ] && value[ Object.keys( value )[ 0 ] ] === this[ index ][ Object.keys( this[ index ] )[ 0 ] ];
}, tab2 );
}
return tab3;
};
console.log( diff( array2, array1 ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment