Skip to content

Instantly share code, notes, and snippets.

@Rendez
Created January 22, 2011 13:28
Show Gist options
  • Save Rendez/791123 to your computer and use it in GitHub Desktop.
Save Rendez/791123 to your computer and use it in GitHub Desktop.
Array.diff
Array.implement({
diff: function() {
var r = [], idx = -1, diff, len, i, pos, array, keys;
keys = ((keys = arguments[arguments.length-1]) === true);
while(n < arguments.length) {
array = arguments[n++];
for(len = array.length, pos = this.length; len--;){
for(i = pos; i && (diff = array[len] !== this[--i]););
diff && (r[++idx] = keys ? len : array[len]);
}
return r;
}
return [];
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment