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

var summatory = 0;

function animate() {
  $('#result').text(counter++);
  if (counter <= counterEnd) {
  
    //Calculate dinamically newInterval
    var newInterval = countInterval;
    
    summatory += newInterval;
    console.log(newInterval);
    countInterval = newInterval;
    setTimeout(animate, newInterval);
  } else {
  	$('#summatory').text(summatory); //should be 2000
  }
}

animate();