Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Range Generator

Beyond the Courseeasy

Implement `rangeArray(n)` using a generator function that yields `0` to `n-1`, collecting the values into an array.

Sample tests

Input: rangeArray(3)
Output: [0,1,2]
Input: rangeArray(0)
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Forgetting the star, making it a normal function.

Learning resources

  • MDN: Iterators and generators
Visualize this concept: Iterators and Generators →
Approach & explanation (try first)

A generator yields each value lazily; spreading drains it into an array.

Loading...
⌘/Ctrl + Enter

Run your code to see results.