JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Skip to content
Gallery
JS Fundamentals: Objects, Arrays, and Functions
Introduction
Content
Bonus: Merge Sort
More
Share
Explore
Functions
Exercise: Implement map
Tweet me that you did the exercise!
Prompt
Implement
map
, that creates an array of values by running each element in collection thru a callback.
The callback is invoked with three arguments: (value, index|key, collection).
Definition:
map(collection, callback)
Example Usage:
console.
log
(
map
([
1
,
2
,
3
], number => number +
1
));
// => [2, 3, 4]
console.
log
(
map
({a:
1
, b:
2
}, number => number +
1
));
// => { a: 2, b: 3 }
Code here
Loading…
https://replit.com/@BiancaGandolfo/exercise-map#index.js
Solution
The solution is in the solution branch, which can be checked out in the
Repl.it
by selecting the version control tab on the right and then selecting the solution branch from the drop down menu.
If you are having trouble with
repl.it,
the solutions are also available below.
map Solution
Next 👉
Exercise: Implement filter
©2021
Code and Coffee
for
Frontend Masters
Prompt
Code here
Solution
map Solution
Next 👉 Exercise: Implement filter
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
Ctrl
P
) instead.