JavaScript Iterables — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Iterables lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Confirm an array is iterable
easy10 minReport the type of an array's Symbol.iterator method.
- 2
Loop over a Set
easy10 minUse for of to collect values from a Set.
- 3
Catch a non-iterable loop
easy10 minCatch the error from looping over a plain object.
- 4
Spread a string
easy10 minSpread a string into an array of its characters.
- 5
Tell iterable spread from object spread
medium10 minShow both kinds of spread working on their own kind of value.
Find the bug(5)
- 1
Fix for of used on a plain object
easy8 minPlain objects are not iterable.
- 2
Fix the spread of a plain object as a list
easy8 minSpreading an object into an array position needs it to be iterable.
- 3
Fix the Map assumed non-iterable
easy8 minA Map is iterable, yielding key-value pairs.
- 4
Fix the string spread miscounted
easy8 minSpreading a string gives one entry per character, not per byte pair blindly assumed.
- 5
Fix destructuring used on a non-iterable
easy8 minArray destructuring needs an iterable on the right side.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace