There is a function that should turn over an array (like the reverse method):

function reversed(arr) { for (var i = arr.length; i > 0; i--) { var elem = arr.pop(); arr.unshift(elem); } return arr; } var testArr = [1, 2, 3, 4, 5, 6, 7, 8]; console.log(reversed(testArr)); 

But the initial array is returned.

  • The unshift method does not sort the entire array in the reverse order, that is, it does not make the first element the last, the second the last but one, and so on. Besides, using this method is stupid to pass one element to it. Read the documentation carefully. - Quazimorda

1 answer 1

Error logic - is like trying to turn the stack, each time taking the top and putting it on the bottom.

 function reversed(arr) { for (var reversed = []; arr.length > 0; reversed.push(arr.pop())); return reversed; } var testArr = [1, 2, 3, 4, 5, 6, 7, 8]; console.log(reversed(testArr));