Skip to content

Instantly share code, notes, and snippets.

@zykadelic
Created March 25, 2014 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zykadelic/9766954 to your computer and use it in GitHub Desktop.
Save zykadelic/9766954 to your computer and use it in GitHub Desktop.
Returns a new array without any occurrence of the argument.
Array.prototype.remove = function(obj){
// Copy the array, so we don't override it
var array = this.slice(0);
for(var i = 0; i < array.length; i++){
// Use while-loop to find adjacent equal objects
while(array[i] === obj){
// Remove this[i]
array.splice(i, 1)[0];
}
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment