Skip to content

Instantly share code, notes, and snippets.

@max2320
Created October 10, 2017 18:03
Show Gist options
  • Select an option

  • Save max2320/1e1d8ab728926c370ca16c9b2591c6c4 to your computer and use it in GitHub Desktop.

Select an option

Save max2320/1e1d8ab728926c370ca16c9b2591c6c4 to your computer and use it in GitHub Desktop.
How to implement a map algorithm in js
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);
}
@max2320
Copy link
Copy Markdown
Author

max2320 commented Oct 10, 2017

ES5 for while

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment