How does Javascript array.reverse() ? Does it go through and replace every element of the array? If so, is it necessary to take an O (n) array of size n?
I think the reason I'm asking for is because I was wondering if array.reverse() the same as:
for(var i = 0; i < a.length / 2; i++) { var holder = a[i]; a[i] = a[a.length - 1 - i]; a[a.length - 1 - i] = holder; }
NOTE : Sorry if the Javascript code I posted is incorrect, it is now quite late.
EDIT : Fixed a.length - a.length / 2 .
Ivan
source share