-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay30.js
More file actions
23 lines (19 loc) · 869 Bytes
/
Day30.js
File metadata and controls
23 lines (19 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//* Coding Challenge: Number Range Generator Using Recrusive function
//*-
//? Write a function called numberRangeRecursive that generates an array containing consecutive numbers from a to b (inclusive).
//* Input:
//? a: An integer representing the starting number of the range.
//? b: An integer representing the ending number of the range.
//? arr: An optional parameter representing the array to store the numbers in the range. It defaults to an empty array.
//* Output :
//? An array containing consecutive numbers from a to b (inclusive).
//* Constraints:
//? a and b will be integers.
//? a will be less than or equal to b
const numberRangeRecursive = (a, b,arr=[]) =>{
if(a<=b){
arr.push(a);
}
}
console.log(numberRangeRecursive (0, 5)); // Output: [0, 1, 2, 3, 4, 5]
console.log(numberRangeRecursive (-2, 2)); // Output: [ -2, -1, 0, 1, 2 ]