Slide 1

Slide 1 text

@angustweets JavaScript is Literature is JavaScript.

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

The Mother of all Code Reviews...

Slide 5

Slide 5 text

Excercise 1: fibonnaci numbers

Slide 6

Slide 6 text

Ernest Hemingway “All my life I've looked at JavaScript as though I were seeing it for the first time”

Slide 7

Slide 7 text

function fibonacci(size) { var first = 0, second = 1, next, count = 2; var result = [first, second]; if(size < 2) return "the request was made but it was not good" while(count++ < size) { next = first + second; first = second; second = next; result.push(next); } return result; }

Slide 8

Slide 8 text

William Shakespeare “So foul and fair a language I have not seen”

Slide 9

Slide 9 text

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 FORLOOP

Slide 10

Slide 10 text

//ACT I: in which a ZERO is added for INITIATION //[ENTER: theResult] //Upon the noble list bestow a zero var theResult = [0];

Slide 11

Slide 11 text

//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)]; }

Slide 12

Slide 12 text

//'Tis done, and here's the answer. return theResult; //[Exeunt] }

Slide 13

Slide 13 text

André Breton “The man who can't visualize a horse galloping on a tomato is an idiot”

Slide 14

Slide 14 text

function Colette(umbrella) { var staircase = galleons = 0; var brigantines = 1, bassoon; var armada = [galleons, brigantines]; Array.prototype.embrace = [].push; while(2 + staircase++ < umbrella) { bassoon = galleons + brigantines; armada.embrace( brigantines = (galleons = brigantines, bassoon)); } return armada; }

Slide 15

Slide 15 text

Roberto Bolaño “We're programmers, but we do a good job hiding it”

Slide 16

Slide 16 text

function LeonardoPisanoBigollo(l) { if(l < 0) { return "I'd prefer not to respond."\ "(Although several replies occur to me)" } /**/ //Everything is getting complicated. for (vari=2,r=[0,1].slice(0,l); i

Slide 17

Slide 17 text

//Here are some other mathematicians. //Mostly it's just nonsense. rationalTheorists = ["Archimedes of Syracuse", "Pierre de Fermat (such margins, boys!)", "Srinivasa Ramanujan", "Rene Descartes", "Leonhard Euler", "Carl Gauss", "Johann Bernoulli", "Jacob Bernoulli", "Aryabhata", "Brahmagupta", "Bhaskara II", "Nilakantha Somayaji", "Omar Khayyám", "Muhammad ibn Mūsā al-Khwārizmī", "Bernhard Riemann", "Gottfried Leibniz", "Andrey Kolmogorov", "Euclid of Alexandria", "Jules Henri Poincaré", "Srinivasa Ramanujan", "Alexander Grothendieck (who could forget?)", "David Hilbert", "Alan Turing", "von Neumann", "Kurt Godel", "Joseph-Louis Lagrange", "Georg Cantor", "William Rowan Hamilton", "Carl Jacobi", "Évariste Galois", "Nikolay Lobachevsky", "Rene Descartes", "Joseph Fourier", "Pierre-Simon Laplace", "Alonzo Church", "Nikolay Bogolyubov"]

Slide 18

Slide 18 text

//I didn't understand any of this, //but here it is anyway. return r /**/ //Nothing happens here //and if it does I'd rather not talk about it. }

Slide 19

Slide 19 text

Charles Dickens “There is a wisdom of the Head, there is a wisdom of the Heart...and then there's JavaScript”

Slide 20

Slide 20 text

function mrFibbowicksNumbers(enormity) { var assortment = [0,1,1], tally = 3; var artfulRatio = 1.61803; while(tally++ < enormity) { //here is an exceedingly clever device assortment.push( Math.round( assortment[tally-2] * artfulRatio)); } //should there be an overabundance of //elements, a remedy need be applied return assortment.slice(0, enormity); }

Slide 21

Slide 21 text

Excercise 2: factorial(n)

Slide 22

Slide 22 text

Jack Kerouac “All of JavaScript is a foreign country”

Slide 23

Slide 23 text

/*...the only numbers for me are the mad ones, take forty-three like a steam engine with a talky caboose at the end*/ n = 43, /*and that lanky fellow in a cocked fedora*/ r = 1 /*then back to our number, our mad number, mad to become one*/ while (n > 1) /*mad to descend*/ n--, /*mad to multiply*/ r = r * n /*and at the end, you see the blue center-light pop, and everybody goes 1.4050061177528801e+51...*/ r

Slide 24

Slide 24 text

James Joyce “Writing in JavaScript is the most ingenious torture ever devised for sins committed in previous lives”

Slide 25

Slide 25 text

function hacktorial(integette) { var nonthings = [undefined, null, false, 0, '']; var resultution = 1; if (integette == 0) { //behold the strangerous zeroine! resultution = 1; } else { while (integette > 1) //caligulate by multicapables resultution = resultution * integette--; }

Slide 26

Slide 26 text

with(resultution) { var duodismal = Function('return this').call(toString(12)); var disemvowel = Function("n","return n?parseInt(n,12):'0'") return [ disemvowel(duodismal.slice(0,-1)), 'shillings and', disemvowel(duodismal[duodismal.length-1]), 'pence' ].join(' '); } //klikkaklakkalopatcreppycrottyladdypkonpkot! }

Slide 27

Slide 27 text

hacktorial(3) //"0 shillings and 6 pence" hacktorial(4) //"2 shillings and 0 pence" hacktorial(7) //"420 shillings and 0 pence"

Slide 28

Slide 28 text

Richard Feynman “I never pay attention to anything by experts. I program everything myself”

Slide 29

Slide 29 text

//using Ramanujan's approximation function fractorail(n){ with(Math) { var r = sqrt(PI)*pow(n/E,n); r *= pow(8*pow(n,3)+4*(n*n)+n+(1/30), 1/6); return r; } } fractorail(3); //6.00005 fractorail(1.1); //1.04671 fractorail(5.2); //169.40628

Slide 30

Slide 30 text

Arthur Conan-Doyle “I Never Throw Exceptions. An Exception Disproves The Rule”

Slide 31

Slide 31 text

"use strict"; //In solving a problem of this sort, the //grand thing is to be able to reason backwards //some things are easier known than explained! var caseHistory = new Object({2:2, 6:3}); function unfactorial(evidence){ //first, humility! if (evidence === 1) { return "Watson, I am at a loss!" } //second, logical precedence! if(caseHistory[evidence]){ //elementary! return caseHistory[evidence]; }

Slide 32

Slide 32 text

//third, eliminate the impossible! if(evidence === 0 || evidence % 24 !== 0) { return "charlatans!"; } //fourth, deduction! var theDeduction; var enumarator = evidence, denominator = 1; while(enumarator % denominator === 0) { enumarator = enumarator/denominator++; if (enumarator === denominator) { theDeduction = enumarator; } }

Slide 33

Slide 33 text

theDeduction = theDeduction || "impostors"; //What one man can invent another can discover! caseHistory[evidence] = theDeduction; //What remains, however improbable, is truth! return theDeduction; } unfactorial(2); //2 unfactorial(120); //5 unfactorial(25); //‘charlatans!’ unfactorial(1); //‘Watson, I am at a loss!’

Slide 34

Slide 34 text

Samuel Johnson “When one is tired of JAVA-SCRIPT one is tired of LIFE”

Slide 35

Slide 35 text

# In which various NUMBERS are summon'd by # means of ELECTRONICK CONJURY factorial = (n) -> # All argument is against it; # yet all belief is for it return 1 unless n # Ingenious sophistry to prove # the palp'bly OBVIOUS return 1 if n is 1 # Recursion (n.) # a program that calls 'pon itself in the # manner of a dog returning unto its VOMIT n * factorial n - 1

Slide 36

Slide 36 text

Jane Austen “A programmer, especially if she have the misfortune of knowing anything, should conceal it as well as she can”

Slide 37

Slide 37 text

factorial = (function() { //I declare... var ledger = {}; return function reckoning(quantity) { if (isNaN(quantity)) { console.log("I have not the pleasure of"\ "understanding you"); return; } //It is a truth universally acknowledged that //two values can only be adjudged truly //agreeable by means of the === operator if (quantity === 0) { return 1; }

Slide 38

Slide 38 text

//Mr Crockford teaches that we be wary of //inherited property... if (ledger.hasOwnProperty(quantity)) { return ledger[quantity]; } //Pray persist until an answer is furnished return ledger[quantity] = quantity * reckoning(quantity - 1); }; })(); factorial(4); //24 factorial(9); //362880

Slide 39

Slide 39 text

Ernest Hemingway “When you stop writing JavaScript for fun you might as well be dead”

Slide 40

Slide 40 text

//Economy. function factorial(n) { return n < 2 ? 1: factorial(n-1)*n; }

Slide 41

Slide 41 text

If Edgar Allan Poe Wrote JavaScript Once upon a midnight dreary, while I struggled with JQuery, Sighing softly, weak and weary, troubled by my daunting chore, While I grappled with weak mapping, suddenly a function wrapping formed a closure, gently trapping objects that had gone before. Ah, distinctly I remember, it was while debugging Ember, As each separate dying member left its host for ever more. Eagerly I wished the morrow–vainly I had sought to borrow (From my bookmarked trail of sorrow), APIs from Underscore. There I sat engaged in guessing the meaning of each cursed expression, Endless callbacks in procession; nameless functions, nothing more, This and more I sat divining, strength and spirit fast declining, Disclose the value we're assigning! Tell me - tell me, I implore!

Slide 42

Slide 42 text

@angustweets The End. byfat.xxx/if-hemingway-wrote-javascript blog.anguscroll.com/if-edgar-allen-poe- wrote-javascript anguscroll.com github.com/angus-c/literaryJavaScript

Slide 43

Slide 43 text

photo credits Title page: 25.media.tumblr.com/tumblr_m5yygfWYG81qa3d0ro1_500.jpg Hemingway: asburyandasbury.typepad.com/.a/6a010535893544970c014e8a5efee9970d-800wi Shakespeare: multimedia.pol.dk/archive/00494/BRITAIN_SHAKESPEARE_494975a.jpg Breton: 24.media.tumblr.com/23eacc5ea0112720e40df9bccade5067/tumblr_mih1x7me9r1qzn0deo1_1280.jpg Bolaño: blogs.20minutos.es/trasdos/files/2013/03/1-99-Gerona-abril-1981ok.jpg Dickens: www.heritagedaily.com/wp-content/uploads/2011/10/dickins.jpg Austen: imgs.mi9.com/uploads/movie-tv/1480/anne-hathaway-jane-austen-in-becoming-jane_1024x768_20809.jpg Kerouac: 24.media.tumblr.com/5a1173c4afb79c43d0d6abab2023c6d2/tumblr_mmebqdafaL1qzt15co1_1280.jpg Joyce: sdsouthard.files.wordpress.com/2012/02/joyce.jpg Feynman: i1.ytimg.com/vi/HmbTbtWoWwY/maxresdefault.jpg Conan Doyle: bookishman.files.wordpress.com/2013/01/basil-rathbone-as-sherlock-holmes.jpeg Johnson: ebooks.adelaide.edu.au/j/johnson/samuel/portrait.jpgext