Skip to content

Instantly share code, notes, and snippets.

@colonelrascals
Created June 28, 2018 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colonelrascals/887f26bb5b2a61b6ce086072088857b6 to your computer and use it in GitHub Desktop.
Save colonelrascals/887f26bb5b2a61b6ce086072088857b6 to your computer and use it in GitHub Desktop.
JavaScripts map function deconstructed
//--Write your own map() function
//
//--Input: array, callback funtion
//
//--Output: new array where every element is transformed by the callback function
const map = (array, callback) => {
let newArr = [];
for (var i = 0; i < array.length; i++) {
newArr[i] = callback(array[i], i)
}
return newArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment