Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Collect from a Start

Beyond the Coursemedium

Implement `collectGen(start, count)` using a generator that yields `count` consecutive integers beginning at `start`, collected into an array.

Sample tests

Input: collectGen(5, 3)
Output: [5,6,7]
Input: collectGen(0, 0)
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Off-by-one producing one too many or too few values.

Learning resources

  • MDN: Iterators and generators
Approach & explanation (try first)

The generator yields start through start+count-1, collected by spreading.

Loading...
⌘/Ctrl + Enter

Run your code to see results.