Created
March 25, 2014 17:32
-
-
Save zykadelic/9766954 to your computer and use it in GitHub Desktop.
Returns a new array without any occurrence of the argument.
This file contains 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
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