Skip to content

Instantly share code, notes, and snippets.

@Akifcan
Created July 28, 2024 15:28
Show Gist options
  • Save Akifcan/8f328e266d7f3e1f4dbfc34aef4bdfec to your computer and use it in GitHub Desktop.
Save Akifcan/8f328e266d7f3e1f4dbfc34aef4bdfec to your computer and use it in GitHub Desktop.
my map polypill
const nums = [17, 1, 2, 3, -1]
const obj = (x) => {
return {initial: x, square: x*x, positive: Math.sign(x) > 0 ? true : false}
}
Array.prototype.myMap = function(cb){
const output = []
for(let i = 0; i<this.length; i++){
output.push(cb(this[i]))
}
return output
}
console.log(nums.myMap(obj))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment