I have been trying to reverse an array, first by using push and creating a new array, and then second by using destructuring and mutating the original array.
I'm wondering which of the two runs faster, and why?
Assuming your code is optimized:
O(n^2)
, 2: O(n+1)
).O(n)
, 2: O(n/2)
).Also note that may use the built-in
Array.prototype.reverse()
method as well.