countdown
with two parameters. The function should take an array in the myArray
parameter and append the numbers n through 1 based on the n
parameter.
For example, calling this function with n = 5
will pad the array with the numbers [5, 4, 3, 2, 1]
inside of it.
Your function must use recursion by calling itself and must not use loops of any kind.
countdown(myArray, -1)
, myArray should be empty.
testString: assert.isEmpty(padArray([], -1));
- text: After calling countdown(myArray, 10)
, myArray should contain [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
testString: assert.deepStrictEqual(padArray([], 10), [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
- text: After calling countdown(myArray, 5)
, myArray should contain [5, 4, 3, 2, 1]
testString: assert.deepStrictEqual(padArray([], 5), [5, 4, 3, 2, 1]);
- text: Your code should not rely on any kind of loops (for
or while
or higher order functions such as forEach
, map
, filter
, or reduce
.).
testString: assert(!removeJSComments(code).match(/for|while|forEach|map|filter|reduce/g));
- text: You should use recursion to solve this problem.
testString: assert(removeJSComments(countdown.toString()).match(/countdown\s*\(.+\)\;/));
```