time is going fast, career change to do the whole year, to go out to see the world. See what level I can now level, to determine the future direction of learning, but also look at the outside of the company are using some of the technology.
Yesterday, a company, the other side directly let me answer the question of the finale. A simple algorithm design problem: Familiar with JS classmate know JS in the string has a indexof method, now need to implement the IndexOf method of the array. As the undergraduate is not a computer major, some of the basic programming skills are not solid (such as the basic Algorithm mastery degree, algorithm design capabilities), yesterday did not do the right thing. Write it out today so that you don't have to think about it later. Luo Li bar a meal, on the code bar or:
1Array.prototype.indexOf =function(b) {2 //parameter Check3 if(Object.prototype.toString.call (b)!== ' [Object Array] ')return NewError (' array expected ');4 //The length of B is longer than the length of this array and returns directly5 if( This. length < B.length)return-1;6 7 varindex = 0,//this array cursor8i = 0,9Len =b.length;Ten while(Index < This. Length) { One if( This. Length-index < B.length)return-1; A for(i = 0; i < Len; + +)i) { - if( This[Index + i]!== b[i]) Break; - } the if(i = = = B.length)returnindex; -index++; - } -}
IndexOf method of implementing array in JS