Combine two arrays with concat and show the result joined by commas.
Acceptance criteria
- 1.#out should show 1,2,3,4.
JavaScript Tutorial · JavaScript Arrays
These 10 tasks go with the JavaScript Array concat and join 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 concat joins two arrays together and join turns an array into a string.” .
1.Join two arraysexercise · easy · 10 min
Combine two arrays with concat and show the result joined by commas.
Passes when: #out should show 1,2,3,4.
2.Combine with spreadexercise · easy · 10 min · practice plan
Combine two arrays using spread instead of concat.
Passes when: #out should show a,b,c,d.
3.Choose a separatorexercise · easy · 10 min · practice plan
Join a list of words using a space, the word and, and another space.
Passes when: #out should show salt and pepper.
4.Glue letters togetherexercise · easy · 10 min · practice plan
Join an array of letters with no separator at all.
Passes when: #out should show code.
5.Join three arraysexercise · medium · 10 min · practice plan
Concat three arrays in one call and show the total length.
Passes when: #out should show 6.
6.Fix concat that was thrown awaybug fix · easy · 8 min
concat returns a new array; it does not change the original.
Passes when: #out should show 1,2,3,4.
7.Fix the array pushed instead of joinedbug fix · easy · 8 min · practice plan
Pushing an array adds it as a single nested element.
Passes when: #out should show a,b,c,d.
8.Fix the wrong separatorbug fix · easy · 8 min · practice plan
The list should read as a sentence, not a comma list.
Passes when: #out should show salt and pepper.
9.Fix join called without a separatorbug fix · easy · 8 min · practice plan
The default separator adds commas between the letters.
Passes when: #out should show code.
10.Fix the spread that was missedbug fix · easy · 8 min · practice plan
Without spread the arrays end up nested instead of merged.
Passes when: #out should show flat 4.
Between them these tasks cover concat, join and Spread.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.