Hướng dẫn thử thách
1 / 1
Build a Range of Numbers Generator
In this lab, you will build a `rangeOfNumbers` function that generates an array of numbers within a specified range.
Examples:
- `rangeOfNumbers(3, 9)` returns `[3, 4, 5, 6, 7, 8, 9]`
- `rangeOfNumbers(5, 5)` returns `[5]`
Requirements:
- Use recursion (the function must call itself)
- No loops or array methods (`for`, `while`, `Array.from`, `forEach`, `map`, `filter`, `reduce`)
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab.
**User Stories:**
1. You should create a function named `rangeOfNumbers` that takes two parameters: `startNum` and `endNum`.
1. The function should return an array of integers that begins with the number represented by the `startNum` parameter and ends with the number represented by the `endNum` parameter (inclusive).
1. The `startNum` will always be less than or equal to the `endNum`.
1. Your function must use recursion by calling itself. It should not use any loop syntax (`for`, `while`, `Array.from()`, or higher-order functions such as `forEach`, `map`, `filter`, or `reduce`).
1. The function should handle the base case where `startNum` equals `endNum` by returning an array containing just that single number.
1. For the recursive case, the function should call itself with modified parameters to build the array, then add the current number to the result.
1. The function should not rely on global variables to cache or build the array.
Vượt qua bài kiểm tra hiện tại để mở khóa bài tiếp theo.
main.js
UTF-8 • Tab Size: 2Kiểm tra bài:⌘↵