Im working through this problem in a javascript book to reverse an array, and I just dont know why this code isnt working. Can someone please explain? This codes supposed to swap the values, but it does nothing to the array.
let nums = [1, 2, 3, 4, 5, 6, 7, 8, 9];
function reverseArrayInPlace(array) {
for (let start = 0, end = array.length - 1; start < array.length, end >= 0; start++, end--) {
let x = array[start];
array[start] = array[end];
array[end] = x;
}
return array;
}
reverseArrayInPlace(nums);
console.log(nums);
array.reverse()method does exist.