DEV Community

Discussion on: How Would You Reverse an Array In Place?

Collapse
 
ionellupu profile image
Ionel Cristian Lupu

This can be done with only the leftPointer. The rightPointer can be deduced from arr.length - leftPointer - 1.

Also, isn't Array.prototype.reverse() O(n)? It looks like, as per spec, they do almost the same thing: