Giter Club home page Giter Club logo

Comments (7)

darrenscerri avatar darrenscerri commented on July 17, 2024 2

I agree, my solution returns [ 0, 10, 20, 30, 40, 50 ] which as per my understanding would by acceptable with respect to the throttle definition that "it will execute every threshold ms". To allow the tests to pass I'm adding 1ms to the ms argument passed to the throttle function.

from exercises.

chemzqm avatar chemzqm commented on July 17, 2024

My result changed a lot
[ 0, 11, 22, 32, 43, 54 ]
[ 0, 12, 22, 32, 42, 52 ]
[ 0, 12, 21, 32, 43, 54 ]

from exercises.

PinkyJie avatar PinkyJie commented on July 17, 2024

I agree, the correct answer should be [ 0, 10, 20, 30, 40, 50 ].
In addition, I think there are 2 more incorrect test cases.

  1. throttle will execute at least once more to make up for swallowed calls:
    • I think the correct answer should be 1.
  2. throttle gets called with the later arguments:
    • I think the correct answer should be [ 11, 22, 33 ]

This article has a fancy animation to illustrate the difference between throttle and debounce.

from exercises.

kolodny avatar kolodny commented on July 17, 2024

I never really gave throttle the proper attention. My first pass at it had the intervals being kicked back into place, for example 10ms kicks at (1,41,63,95,149) => (0, 40, 60, 90, 140), and didn't use mock timers at all. I want to reexamine that approach and also take a closer look at the pending PRs for throttle

from exercises.

mtso avatar mtso commented on July 17, 2024

I am also getting [ 0, 10, 20, 30, 40, 50 ] with sinon's fake timer.

@PinkyJie The rest of the test cases appear to be accurate, given that:

  1. Calls made to throttle during the throttle "cool down" should be collapsed into a single call made at the end of the throttle, so calling the throttled thunk twice within the threshold should make it call once at the beginning, and then once at the end. The thunk should thus be called twice.
  2. The [33, 44, 55] assigned into args is the result of the above test case behavior.

from exercises.

kolodny avatar kolodny commented on July 17, 2024

This is tricky to fix with fake timers, I've switched to use a "kicker" instead. Let me know if it solves this:

https://github.com/kolodny/exercises/tree/fix-time-issues

from exercises.

sunderls avatar sunderls commented on July 17, 2024

met the same problem,

just a mention that lodash.throttle generates
[0,10,20,30,40,50] so I'd say we should stick to lodash

from exercises.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.