function capitalizeFirst(arr, new_arr) {
if (arr.length === 0) return new_arr;
let str = arr.pop();
console.log(str);
return capitalizeFirst(arr, new_arr.push(str));
}
Here is my code. The goal is to practice recursion with this exercise. I am giving the function the following parameters
capitalizeFirst(['car','taco','banana'], []);
new_arr is clearly an array. Why is the push method not working on it? Also, when I change my return statement to
return capitalizeFirst(arr, [].push(str));
and follow along with chrome debugger, the number 1 keeps getting passed to the array instead of the arr.pop() value. What is causing this behavior? I haven't added in the implementation to capitalize the first letter yet either. That was just going to be a replace() call inside my push method in case anyone was wondering why my code wasn't doing what the method name proclaimed.
Thanks for any help