Skip to content

Instantly share code, notes, and snippets.

@dsetzer
Last active November 10, 2019 19:08
Show Gist options
  • Save dsetzer/9baf835d5190a727b4a7d17db0b2e17d to your computer and use it in GitHub Desktop.
Save dsetzer/9baf835d5190a727b4a7d17db0b2e17d to your computer and use it in GitHub Desktop.
// Array remove by shifting elements
Array.prototype.remove = function(index) {
var stop = this.length - 1;
while (index < stop) this[index] = this[++index];
this.pop();
}
// Array filter remove by shifting elements
Array.prototype.filterRemove = function(fn) {
for (var i = 0, j = 0; i < this.length; ++i) {
if (fn(this[i])) { this[j] = this[i]; ++j; }
}
while (j < this.length) this.pop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment