function reverseSubarray(arr, start, end) {
if (end > arr.length) {
console.log("End index out of range");
return;
}
const mid_sub = (end - start + 1) / 2;
for (let i = 0; i < mid_sub; i++) {
let tmp = arr[start + i];
arr[start + i] = arr[end - i];
arr[end - i] = tmp;
}
}
const arr = [ 1, 4, 8, 0, 7, 3, 9, 5, 6 ];
const start = 2, end = 6;
reverseSubarray(arr, start, end);
console.log(arr);
/*
run:
[1, 4, 9, 3, 7, 0, 8, 5, 6]
*/