Created
March 7, 2013 18:29
-
-
Save dbrockman/5110478 to your computer and use it in GitHub Desktop.
JS array insertAt and removeAt function
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
function insertAt(arr, val, i) { | |
arr.splice(i, 0, val); | |
} | |
function removeAt(arr, i) { | |
return arr.splice(i, 1).length === 1; | |
} | |
function genericInsertAt(arr, val, i) { | |
Array.prototype.splice.call(arr, i, 0, val); | |
} | |
function genericRemoveAt(arr, i) { | |
return Array.prototype.splice.call(arr, i, 1).length === 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment