Created
October 5, 2013 21:03
-
-
Save gemfarmer/6845984 to your computer and use it in GitHub Desktop.
The same as .splice(), but without side effects. "replace" can be several items and the funciton will still work cleanly
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
var spliceClean = function(arr, start, numToReplace, replace) { | |
var end = (start+numToReplace-1) | |
var newArray = []; | |
for (i=0; i<arr.length; i++){ | |
(i < start) ? newArray.push(arr[i]) : console.log("rejected") | |
} | |
for (i=3; i<arguments.length; i++){ | |
newArray.push(arguments[i]) | |
} | |
for (i=0; i<arr.length; i++){ | |
(end< i) ? newArray.push(arr[i]) : console.log("rejected") | |
} | |
return newArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment