function reverseArrayInPlace(array) { for (var i = 0; i < Math.floor(array.length / 2); i++) { var old = array[i]; array[i] = array[array.length - 1 - i]; array[array.length - 1 - i] = old; } return array; } */
function reverseArrayInPlace(array) { var b = array.length; for (var i = 0; i < --b; i++) { var swap = array[i]; array[i] = array[b]; array[b] = swap; } return array; }
function reverseArray(array) { var output = []; for (i = array.length - 1; i >= 0 ; i--) { output.push(array[i]); } return output; }
console.log(reverseArray(["A", "B", "C"]));
var arrayValue = [1, 2, 3, 4, 5]; reverseArrayInPlace(arrayValue); console.log(arrayValue);
|