Last active
November 10, 2019 19:08
-
-
Save dsetzer/9baf835d5190a727b4a7d17db0b2e17d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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