Created
January 13, 2016 19:44
-
-
Save tommymarshall/f7d67b23f96dd8716e58 to your computer and use it in GitHub Desktop.
recreating Array.splice from scratch
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.prototype.splicey = function(position, number, values) { | |
if (!position) return this | |
var newNumber = number || this.length | |
var newThis = [] | |
for (var i = position; i <= position + newNumber; i++) { | |
if (values) { | |
if (Array.isArray(values)) { | |
this[i].push(values) | |
} else { | |
var prevPosition = i | |
for (var value in values) { | |
this[prevPosition].push(value) | |
prevPosition++ | |
} | |
} | |
} else { | |
} | |
} | |
return newThis | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment