Skip to content

Instantly share code, notes, and snippets.

@tommymarshall
Created January 13, 2016 19:44
Show Gist options
  • Save tommymarshall/f7d67b23f96dd8716e58 to your computer and use it in GitHub Desktop.
Save tommymarshall/f7d67b23f96dd8716e58 to your computer and use it in GitHub Desktop.
recreating Array.splice from scratch
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