Skip to content

Instantly share code, notes, and snippets.

@joewagner
Created December 28, 2019 05:10
Show Gist options
  • Save joewagner/bd7bbb5026fedb52834a5fe7349f7a7e to your computer and use it in GitHub Desktop.
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
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