In the following code I do not understand why reverseArrayOne does not return the reversed array as compared to reverseArrayTwo. In essence I believe I'm assigning the reversedArray to Array in both cases. link to question http://eloquentjavascript.net/04_data.html#c_F3JsLaIs+m
function reverseArray(array) {
reversedArray = [];
for (i=array.length-1; i>=0; i--) {
reversedArray.push(array[i]);
}
return reversedArray;
}
function reverseArrayOne(array) {
array = reverseArray(array);
return array;
}
function reverseArrayTwo(array) {
reversedArray = reverseArray (array);
for (i=0; i<reversedArray.length; i++) {
array[i] = reversedArray[i];
}
return array;
}
var arrayValue = [1, 2, 3, 4, 5];
reverseArrayOne(arrayValue);
console.log(arrayValue);
// → [1,2,3,4,5]
reverseArrayTwo(arrayValue);
console.log(arrayValue);
// → [5, 4, 3, 2, 1]