Last active
December 16, 2015 12:19
-
-
Save Cycymomo/5434095 to your computer and use it in GitHub Desktop.
Comparaison de tableaux JS
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
/* | |
* 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