Skip to content

Instantly share code, notes, and snippets.

@mfalade
Created September 8, 2018 06:23
Show Gist options
  • Save mfalade/3496f2f636d0338630af240ae65cc278 to your computer and use it in GitHub Desktop.
Save mfalade/3496f2f636d0338630af240ae65cc278 to your computer and use it in GitHub Desktop.
Custom Array Map
Array.prototype.xmap = myCustomArrayMap;
function myCustomArrayMap (action) {
var result = [];
for (var i = 0; i < this.length; i++) {
var args = [this[i], i, this];
result.push(action.apply(null, args));
}
return result;
}
var res = [4, 5, 6].xmap(x => x + 6);
console.log(res, 'map result')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment