Created
October 10, 2017 18:03
-
-
Save max2320/1e1d8ab728926c370ca16c9b2591c6c4 to your computer and use it in GitHub Desktop.
How to implement a map algorithm in js
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.recMap = function(callback){ | |
var cicle = function(current, collection, fnModifier) { | |
console.log(current, collection, fnModifier) | |
if(current < collection.length){ | |
collection[current] = fnModifier(collection[current]); | |
return cicle(current + 1, collection, fnModifier); | |
}else{ | |
return collection; | |
} | |
} | |
return cicle(0, this, callback); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ES5 for while