kolodny / exercises

Some basic javascript coding challenges and interview questions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

throttle-promises expectedHistory seems to be wrong

chemzqm opened this issue · comments

The expectedHistory is

0,1,2,3,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,3,2,1,0

but it should be

0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0

Comparing with this https://github.com/kolodny/exercises/blob/master/throttle-promises/test.js#L36 variable also makes the process stop responsing, don't know the reason

The expected history is correct the way it is. What you listed as your expected history would mean that 5 promises get executed and another 5 won't start until those original 5 have all resolved (which isn't correct). What should happen (and what is correctly being tested already) is that 5 promises get executed right away and as soon as any one of them resolves, another one gets started.

While your solution might only execute a 5 promises at a time (which is correct), it is much less efficient than it could be. Your solution is averaging ~2.5 running promises at any given time while the optimal solution (and what is already being tested) is averaging ~4.5 running promises.