kolodny / exercises

Some basic javascript coding challenges and interview questions
4.23k stars 672 forks source link

Fix 'throttle' a proper timeout of the 'will execute every threshold … #31

Closed 2hu12 closed 9 years ago

2hu12 commented 9 years ago

Fix 'throttle' a proper timeout of the 'will execute every threshold ms' test case.

kolodny commented 9 years ago

Yup, there was a race condition, thanks

kolodny commented 9 years ago

@rnsloan does this fix your throttle solution?

rnsloan commented 9 years ago

@kolodny I have tested the solution provided in the solutions branch against the latest test (with the clock.tick additions) and it is now passing in my environment: iojs v2.2.1 .

rnsloan commented 9 years ago

@kolodny as an aside, I have noticed that underscore's throttle method fails this test in my environment around 20%-30% of the time

1) throttle will execute every threshold ms:

      AssertionError: [ 0, 10, 21, 32, 43, 54 ] deepEqual [ 0, 11, 22, 33, 44, 55 ]
      + expected - actual

       [
         0
      -  10
      -  21
      -  32
      -  43
      -  54
      -  65
      +  11
      +  22
      +  33
      +  44
      +  55
       ]
kolodny commented 9 years ago

hmm, maybe I should allow a fudge factor then