Last active
September 10, 2016 18:58
-
-
Save dengjonathan/9eb31ffcaf2c1ca8ad2a8b24b5ec4677 to your computer and use it in GitHub Desktop.
Naive implementations of each and 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
names2 = ['kendra', 'kim', 'kampbell']; | |
// use this as your callback function in map | |
var capitalize = function(word) { | |
return word[0].toUpperCase() + word.slice(1); | |
}; | |
// we need each implemented for map to work | |
var each = function(array, callback) { | |
for (var i = 0; i < array.length; i++) { | |
callback(array[i]); | |
} | |
}; | |
/* | |
QUESTION: create a map function that takes two arguments, an array, and a callback function, | |
and returns a new array with all the items in the array transformed using the callback function | |
*/ | |
var map = function(array, callback) { | |
// YOUR CODE HERE | |
}; | |
map(names, capitalize); // ['Kendra', 'Kim', 'Kampbell'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment