Last active
February 27, 2016 17:01
-
-
Save abarnash/2c9b6b2d60392e9018f3 to your computer and use it in GitHub Desktop.
ES5 implementation of set difference for JS arrays.
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
var array_subtract = function(arr,values) { | |
return arr.filter(function(x) { | |
var remove = values.filter(function(v){ | |
return x == v; | |
}); | |
return !remove.length>0; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// array_subtract([1,2,3,4,5,6,7,7,'hey','b','c'],[4,6,7,'c'])
// [1, 2, 3, 5, "hey", "b"]