Serve the Queue by Hand
JavaScript
20 pts
Serve the Queue by Hand
Do by hand what for…of does for you.
- Write
isIterable(value)that returnstruewhenvalue[Symbol.iterator]is a function, otherwisefalse(test it with arrays, strings, numbers and booleans). - Get an iterator with
queue[Symbol.iterator](). Store the firstnext()result inlet step. With awhileloop, print"Serving " + step.valueas long asstep.doneis false, and get the next step each round. Do not usefororforEach. - Print
step.doneat the end, and testisIterable.
Expected output:
Serving Selam Serving Abel Serving Ruta Queue done: true true false
Checklist
- Write
isIterable(value). - Serve the queue with an iterator,
next()and awhileloop. - Print the serving lines, the done line and the isIterable test.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
