Created
April 5, 2020 19:21
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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