Home > front end >  Dear Daniel, Andy for help: technical problems to solve!!!!!!
Dear Daniel, Andy for help: technical problems to solve!!!!!!

Time:09-23

Apply for Web front-end development engineer, the interviewer's questions: 1, please to implement a brief timeOutEach methods Array, works as follows: every certain time (such as m seconds) outputs a item, if this Array has n items, the timeOutEach method requires n * m long time was able to finish execution (understandable to handle concurrency issues and implementation method of a queue).
2, enter a interval [n, m], where 0 & lt;=n<=m<=100, if a, b, c are interval [n, m), as much as possible, please find the in the interval [n, m] satisfy conditions: a2 + b2=c2. A, b, c values,
Solving!!!!!!

CodePudding user response:

Recently saw a bit of vue - the source code of the router, which triggered queue hook function, use the similar wording, you can refer to:
 
Var arr=[' liu ', 2, '456')
The function itor (item, cb) {
The new Promise ((resolve, reject)=& gt; {
SetTimeout ()=& gt; {
The console. The log (' item 'item);
The resolve ()
}, 2000)
}). Then (cb)
}
The function runQueue (arr, itor, cb) {
Var step index of==& gt; {
If (index>=arr. Length) {
Cb ()
} else {
Itor (arr [index], ()=& gt; {
Step (index + 1)
})
}
}
Step (0)
}
RunQueue (arr, itor, ()=& gt; {the console. The log (' over ')})
  • Related