Skip to content

Instantly share code, notes, and snippets.

@bitfishxyz
Created January 19, 2020 01:06
Show Gist options
  • Save bitfishxyz/f11728098e6cd8ac8ef49f6c03771788 to your computer and use it in GitHub Desktop.
Save bitfishxyz/f11728098e6cd8ac8ef49f6c03771788 to your computer and use it in GitHub Desktop.
const selfMap = function (fn, context) {
let arr = Array.prototype.slice.call(this)
let mappedArr = Array()
for (let i = 0; i < arr.length; i++) {
if (!arr.hasOwnProperty(i)) continue;
mappedArr[i] = fn.call(context, arr[i], i, this)
}
return mappedArr
}
Array.prototype.selfMap = selfMap;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment