Collect three letters into an array and join them into one string.
Acceptance criteria
- 1.#out should show abc.
DSA Tutorial · Strings
These 10 tasks go with the Strings in JavaScript for DSA 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 strings cannot be changed. Every operation that looks like editing one is really building a new one, and that single fact explains most string performance problems.” .
1.Build with joinexercise · easy · 10 min
Collect three letters into an array and join them into one string.
Passes when: #out should show abc.
2.Count charactersexercise · easy · 10 min · practice plan
Show how many characters the word holds, as a word.
Passes when: #out should show five long.
3.Slice a sectionexercise · easy · 10 min · practice plan
Take characters two through four and show them.
Passes when: #out should show ell.
4.Count code pointsexercise · easy · 10 min · practice plan
Use spread to count what a person would call characters.
Passes when: #out should show three chars.
5.Count with a Mapexercise · medium · 10 min · practice plan
Count how many times the letter l appears.
Passes when: #out should show l appears 2.
6.Fix the attempted character writebug fix · easy · 8 min
Strings are immutable, so assigning to an index silently does nothing.
Passes when: #out should show Xbc.
7.Fix the slice boundsbug fix · easy · 8 min · practice plan
The second argument to slice is exclusive, so this takes one character too few.
Passes when: #out should show ell.
8.Fix length used on an emojibug fix · medium · 8 min · practice plan
length counts code units, so an emoji counts as two.
Passes when: #out should show three chars.
9.Fix the counter overwritingbug fix · easy · 8 min · practice plan
Setting the count to one every time never accumulates.
Passes when: #out should show l appears 2.
10.Fix join adding separatorsbug fix · easy · 8 min · practice plan
join with no argument inserts commas between the characters.
Passes when: #out should show abc.
Between them these tasks cover Immutability, Building output and Code points.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.