Use map to double each value and join the result with commas.
Acceptance criteria
- 1.#out should show 2,4,6.
JavaScript Tutorial · JavaScript Arrays
These 10 tasks go with the JavaScript Array map chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “JavaScript map builds a new array by running a function on every element.” .
1.Double every numberexercise · easy · 10 min
Use map to double each value and join the result with commas.
Passes when: #out should show 2,4,6.
2.Pull out a propertyexercise · easy · 10 min · practice plan
Turn an array of user objects into a comma-separated list of names.
Passes when: #out should show Ada,Grace.
3.Uppercase every wordexercise · easy · 10 min · practice plan
Map a list of words to uppercase and join them with spaces.
Passes when: #out should show RED GREEN.
4.Number the listexercise · easy · 10 min · practice plan
Use the index to build a numbered list separated by pipes.
Passes when: #out should show 1:Ada|2:Grace.
5.Show map keeps the originalexercise · medium · 10 min · practice plan
Map a list to doubles and show the original still joined by commas.
Passes when: #out should show 1,2,3.
6.Fix the missing returnbug fix · easy · 8 min
A callback with braces must return a value.
Passes when: #out should show 2,4,6.
7.Fix forEach used instead of mapbug fix · easy · 8 min · practice plan
forEach gives nothing back, so there is no new array.
Passes when: #out should show 10,20.
8.Fix the whole object returnedbug fix · easy · 8 min · practice plan
Only the name should come out, not the object itself.
Passes when: #out should show Ada,Grace.
9.Fix the result never usedbug fix · easy · 8 min · practice plan
map returns a new array; the original is left unchanged.
Passes when: #out should show red!,green!.
10.Fix the index used as the valuebug fix · easy · 8 min · practice plan
The first argument is the value, not the position.
Passes when: #out should show 10,20,30.
Between them these tasks cover map, Transforming data and Callbacks.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.