Skip to content

Instantly share code, notes, and snippets.

@abarnash
Last active February 27, 2016 17:01
Show Gist options
  • Save abarnash/2c9b6b2d60392e9018f3 to your computer and use it in GitHub Desktop.
Save abarnash/2c9b6b2d60392e9018f3 to your computer and use it in GitHub Desktop.
ES5 implementation of set difference for JS arrays.
var array_subtract = function(arr,values) {
return arr.filter(function(x) {
var remove = values.filter(function(v){
return x == v;
});
return !remove.length>0;
});
};
@abarnash
Copy link
Author

// array_subtract([1,2,3,4,5,6,7,7,'hey','b','c'],[4,6,7,'c'])
// [1, 2, 3, 5, "hey", "b"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment