Implement Range

EasyUtility Functions10 min4 tests

Implement a range function that generates an array of numbers.

Requirements

  • range(end) — numbers from 0 to end (exclusive)
  • range(start, end) — numbers from start to end (exclusive)
  • range(start, end, step) — with custom step

Example

range(5);        // [0, 1, 2, 3, 4]
range(2, 6);     // [2, 3, 4, 5]
range(0, 10, 3); // [0, 3, 6, 9]
Hints (3)
  1. Handle argument overloading: if only one arg, treat it as end with start=0.
  2. Default step to 1 if not provided.
  3. Use a for loop from start to end (exclusive) incrementing by step.

Topics

  • Utility Functions

Asked at

Apple · Microsoft

Join Us
blur