-
-
Save libook/50e037f677daece8dade to your computer and use it in GitHub Desktop.
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
// returns things in array 'a' that are not in array 'b' | |
// > ['a','b','c','1', '2', '3'].complement(['b', 'c', 'd', 'e']); | |
// ['a', '1', '2', '3'] | |
function complement(a, b){ | |
(b)||(b=a, a=this); | |
return (Array.isArray(a) && Array.isArray(b)) | |
? a.filter(function(x){return b.indexOf(x)===-1;}) | |
: undefined; | |
} | |
Array.prototype.complement=complement; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment