Skip to content

Instantly share code, notes, and snippets.

@funador
Last active May 26, 2019 20:34
Show Gist options
  • Save funador/fca9277ad8da161c985d437349ce0586 to your computer and use it in GitHub Desktop.
Save funador/fca9277ad8da161c985d437349ce0586 to your computer and use it in GitHub Desktop.
Array.prototype.myMap = function(callback) {
const arr = []
for (let i = 0; i < this.length; i++) {
arr.push(callback(this[i], i , this))
}
return arr
}
const nums = [1, 6, 8]
console.log(nums.myMap(num => num * 2)) // [ 1, 12, 16 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment