I have an array, where I have to swap the first value with last, second with second last, and so on.
I tried doing it like in the code below, but it only works halfway, replacing the other half with zeros. Could somebody explain what is wrong here, please?
for (i = 0; i < arr.length; i++) {
temp = arr[i];
arr[i] = arr[arr.length - 1 - i];
arr[arr.length - 1 - i] = temp;
}