Skip to content
JS Fundamentals: Objects, Arrays, and Functions
Share
Explore
Functions

icon picker
Exercise: Implement map

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…

Solution

The solution is in the solution branch, which can be checked out in the 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 the solutions are also available below.

map Solution

Next 👉


©2021 for

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.