Comments (7)
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.
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.
I agree, the correct answer should be [ 0, 10, 20, 30, 40, 50 ]
.
In addition, I think there are 2 more incorrect test cases.
throttle will execute at least once more to make up for swallowed calls:
- I think the correct answer should be 1.
throttle gets called with the later arguments:
- I think the correct answer should be
[ 11, 22, 33 ]
- I think the correct answer should be
This article has a fancy animation to illustrate the difference between throttle and debounce.
from exercises.
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.
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:
- 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.
- The
[33, 44, 55]
assigned intoargs
is the result of the above test case behavior.
from exercises.
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.
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)
- Create gh-page HOT 2
- link in "curry" prompt goes to incorrect article HOT 1
- Add levels HOT 1
- Test suite for `throttle` appears to be incorrect HOT 5
- The problem of the 4th test suite for `throttle` HOT 2
- a separate repo or folder for solutions could be great HOT 1
- Once and memoize HOT 3
- Is there any order to be followed to approach these exercises? HOT 2
- Example "sort sorts better than n^2" doesn't actually verify the algorithm's time complexity HOT 1
- sinon hack Date Object prevent throttle get passed HOT 2
- throttle-promises expectedHistory seems to be wrong HOT 1
- [SPOILERS] Regarding value solution HOT 3
- flipjs
- You could actually put these tests at codewars.com HOT 1
- Lookup count in binary-search test is not correct HOT 3
- memoize test does not check return value
- Include use-case references
- I'm doing itοΌ show my code
- Error with command: npm test HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from exercises.