« Stolen Names, Common Memes | Main | You've Got To Get Up Pretty Early In The Morning »

If Hemingway Wrote JavaScript

or Shakespeare, for that matter.

Angus Croll:

function theSeriesOfFIBONACCI(theSize) {

//a CALCKULATION in two acts.
//employ'ng the humourous logick of JAVA-SCRIPTE

//Dramatis Personae
var theResult; //an ARRAY to contain THE NUMBERS
var theCounter; //a NUMBER, serv'nt to the FOR LOOP

//ACT I: in which a ZERO is added for INITIATION

//[ENTER: theResult]

//Upon the noble list bestow a zero
var theResult = [0];

//ACT II: a LOOP in which the final TWO NUMBERS are QUEREED and SUMM'D

//[ENTER: theCounter]

//Commence at one and venture o'er the numbers
for (theCounter = 1; theCounter < theSize; theCounter++) {
//By divination set adjoining members
theResult[theCounter] = (theResult[theCounter-1]||1) + theResult[Math.max(0, theCounter-2)];
}

//'Tis done, and here's the answer.
return theResult;

//[Exuent]
}

About

This page contains a single entry from the blog posted on August 13, 2012 10:10 PM.

The previous post in this blog was Stolen Names, Common Memes.

The next post in this blog is You've Got To Get Up Pretty Early In The Morning.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33