Currently, we are delving into functional JavaScript in my programming course with a particular assignment. However, I seem to be struggling to make the code work as intended. I would greatly appreciate any advice on how to improve this piece of code. Everything except for the body was provided for me to utilize. Here is what I have managed to come up with so far: (Unfortunately, it seems to only return the content of the first array index instead of reversing all of them. I attempted changing it to
if(arr.length <= 1) return arr;
however, that adjustment never triggers the base case.)
function ReverseArray(arr) {
//base case
if(arr.length == 1)
{
return arr[0];
}
if(arr.length == 0)
{
return 0;
}
var head = arr.pop;
var newArr = [head, ReverseArray(arr)];
return newArr;
}