Created
June 28, 2018 16:43
-
-
Save colonelrascals/887f26bb5b2a61b6ce086072088857b6 to your computer and use it in GitHub Desktop.
JavaScripts map function deconstructed
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
//--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