Those strange problem of the front end of the interview

(A) Suppose there is an array of 10 000, access time and time Will visit a [0] need to spend a [9999] it takes to tell the difference. (Direct access via the index, does not need to traverse)

The answer : no difference, same time. The group heavyweights original words (no difference, which is a direct take, take the equivalent of the index);

If you are in doubt, look here;

    ARR = the let new new the Array (10000 ); 
    the let T1 = new new a Date (); 
    the console.log (ARR [ 0 ]); 
    the let T2 = new new a Date (); 
    the console.log (T2 - T1); // access arr [0 ] time spent in 
    the console.log (ARR [9999 ]); 
    the let T3 = new new a Date (); 
    the console.log (T3 ; -T2) // temporal access arr [9999] spend

result:

Can be found are 0 ms, do not need to spend the time it takes data, of course, need friends, Date only accurate to the millisecond, it should be too short. (Not quite understand, welcome to correct me)

Well, I do not tangle, and you need to know to access an array indexed by a value whether he is arr [0] or arr [9999] their time are the same.

Guess you like

Origin www.cnblogs.com/tcxq/p/11281772.html