JSFiddle - React, Tailwind, and code Playground
HTML
Counter: <div id="result"></div>
<br><br>
Summatory (should be 2000): <div id="summatory"></div>
JavaScript
var animationLength = 2000; //ms
var counter = 0,
counterEnd = 100,
countInterval = animationLength / counterEnd, // 20 ms,
a = 1.05; //speed factor
var summatory = 0;
function animate() {
$('#result').text(counter++);
if (counter <= counterEnd) {
//that's the formula:
var newInterval = (animationLength-summatory) / ( (a - Math.pow(a, -(counterEnd-1))) / (a-1))
summatory += newInterval;
countInterval = newInterval;
setTimeout(animate, newInterval);
} else {
$('#summatory').text(summatory); //should be 2000
}
}
animate();