Created
September 8, 2018 06:23
-
-
Save mfalade/3496f2f636d0338630af240ae65cc278 to your computer and use it in GitHub Desktop.
Custom Array Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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