Skip to content

Instantly share code, notes, and snippets.

@dengjonathan
Last active September 10, 2016 18:58
Show Gist options
  • Save dengjonathan/9eb31ffcaf2c1ca8ad2a8b24b5ec4677 to your computer and use it in GitHub Desktop.
Save dengjonathan/9eb31ffcaf2c1ca8ad2a8b24b5ec4677 to your computer and use it in GitHub Desktop.
Naive implementations of each and map
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