Skip to content

Instantly share code, notes, and snippets.

@stekhn
Created April 5, 2020 19:21
Show Gist options
  • Select an option

  • Save stekhn/6c80ff4762138e04988fdedc24efc096 to your computer and use it in GitHub Desktop.

Select an option

Save stekhn/6c80ff4762138e04988fdedc24efc096 to your computer and use it in GitHub Desktop.
Calculates the doubling time, hence the time it takes for a certain value to double, assuming exponential growth.
function doublingTime(date1, value1, date2, value2) {
const diff = Math.ceil(date2.getTime() - date1.getTime()) / 86400000;
const days = Math.log(2) * diff / (Math.log(value2) - Math.log(value1));
return days;
}
// Usage:
// doublingTime(new Date('2020-04-01'), 300, new Date('2020-04-05'), 900);
// => 2.523719014285829
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment