Created
April 23, 2020 11:23
-
-
Save imedadel/ac01110c17faf076ed91b5d1869bf393 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
// taken from https://jsperf.com/array-remove-by-index | |
// splice: 6,957,292 ops/sec | |
// swap: 85,501,603 ops/sec (NB. changes order) | |
// shift: 70,903,814 ops/sec | |
// btw. don't actually modify the Array prototype. Create a separate function instead. | |
Array.prototype.mySwapDelete = function arrayMySwapDelete(index) { | |
this[index] = this[this.length - 1]; | |
this.pop(); | |
}; | |
Array.prototype.myShiftDelete = function arrayMyShiftDelete(index) { | |
var stop = this.length - 1; | |
while (index < stop) { | |
this[index] = this[++index]; | |
} | |
this.pop(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment