Skip to content

Instantly share code, notes, and snippets.

@galvez
Created August 12, 2010 16:56
Show Gist options
  • Save galvez/521276 to your computer and use it in GitHub Desktop.
Save galvez/521276 to your computer and use it in GitHub Desktop.
utils = {
subset_of: function(arr) {
for(var i = arr.length, d = {}; i--;) d[arr[i]] = 1;
var p, before = 0, after = 0;
for(p in d) before++;
for(i = this.length; i--;) d[this[i]] = 1;
for(p in d) after++;
return after == before;
}
}
arr = [1,2];
arr.subset_of = utils.subset_of;
console.log(arr.subset_of([2,3,4])); // false
console.log(arr.subset_of([1,2,3,4])); // true
// #flashcodersfeelings
@claus
Copy link

claus commented Aug 12, 2010

LOL

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