MediumPro challengePythonJavaScriptTypeScript
Iterator
TypeScriptDesign PatternsBehavioralIterator
Provide a way to access a collection's elements sequentially without exposing its internal structure — a custom Collection should be usable in a for...of loop just like a built-in array.
Implement `Collection[Symbol.iterator]()`, returning an iterator object whose next() yields { value, done } pairs over the collection's items.
solve(items) adds every item to a Collection, iterates it with for...of, and returns each value doubled.
Sample tests
Test #1Doubles each item in order
Input: [[1,2,3]]
Output: [2,4,6]
Test #2Empty collection
Input: [[]]
Output: []
Test #3Single item
Input: [[5]]
Output: [10]