O'Reilly logo
  • Ignacio Garcia Villanueva thinks this is interesting:

for (var i=numbers.length; i>=0; i--){ 
  numbers[i] = numbers[i-1]; 
numbers[0] = -1; 


Cover of Learning JavaScript Data Structures and Algorithms - Second Edition


Incorrect. This loop will make an array look like this [undefined, x1,x2,x3,...xn] at the end; It would be appropiate to use the following for the loop: for (var i=numbers.length; i>0; i--){ numbers[i] = numbers[i-1]; } So the array will look like this [x1,x1,x2,x3,...,xn]