Problem 21
Recursive Map Recursion Challenge
Given an array and a callback function, return a new array where each element is the result of applying the callback to the corresponding element of the input. Do not use the native Array.prototype.map method.
Function Signature
rMap(array, callback)
Parameters
array— an array of values.callback— a function to apply to each element.
Output
Return a new array of transformed values.
Constraints
- The function must use recursion.
- Do not use
Array.prototype.map. - The input array must not be mutated.
- The function should accept exactly two arguments.
Examples
rMap([1, 2, 3], n => n * 2) → [2, 4, 6]
rMap([1, 2, 3, 4, 5], n => n) → [1, 2, 3, 4, 5]