Created
December 28, 2019 05:10
-
-
Save joewagner/bd7bbb5026fedb52834a5fe7349f7a7e to your computer and use it in GitHub Desktop.
copy paste this into a javascript shell and you'll get 33.33333333333333
This file contains 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
var lim = function (num) { | |
if (num === void 0) num = 100; | |
var series = [100, 50, 25]; | |
var next = function () { | |
var lastTerm = series[series.length - 1]; | |
var secondToLastTerm = series[series.length - 2]; | |
// notice that, since we started above with the first three terms, that the fliping back and forth between adding | |
// and subtracting is handled here ↓, i.e. `secondToLastTerm - lastTerm` is alternating negative and positive | |
var nextValue = lastTerm + ((secondToLastTerm - lastTerm) / 2); | |
series.push(nextValue); | |
} | |
for (var i = 0; i < num; i++) { | |
next(); | |
} | |
return series[series.length - 1]; | |
}; | |
lim(1000); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment