From d04436d9eb9c71e9c1ed97ed0ddd3e3f15d20192 Mon Sep 17 00:00:00 2001 From: Shawn Drost Date: Sun, 25 Nov 2012 15:03:25 -0800 Subject: [PATCH] whitespace and comments --- KoansRunner.html | 2 +- koans/AboutArrays.js | 2 +- koans/AboutHigherOrderFunctions.js | 27 ++++++++++++++---------- koans/AboutInheritance.js | 8 +++++-- koans/AboutObjects.js | 34 +++++++++++++++--------------- 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/KoansRunner.html b/KoansRunner.html index 2b52edd92..f885690dd 100644 --- a/KoansRunner.html +++ b/KoansRunner.html @@ -30,7 +30,7 @@ var passedTestHider = function(){ document.getElementById("__jsKoans_showPassed__").click() } - setTimeout(passedTestHider, 100) //uncomment me in order to hide passed tests by default + // setTimeout(passedTestHider, 100) //uncomment me in order to hide passed tests by default diff --git a/koans/AboutArrays.js b/koans/AboutArrays.js index 147162963..6fe4313cc 100644 --- a/koans/AboutArrays.js +++ b/koans/AboutArrays.js @@ -59,7 +59,7 @@ describe("About Arrays", function() { var array = [ "zero", "one", "two", "three", "four", "five" ]; function passedByReference(refArray) { - refArray[1] = "changed in function"; + refArray[1] = "changed in function"; } passedByReference(array); expect(array[1]).toBe(FILL_ME_IN); diff --git a/koans/AboutHigherOrderFunctions.js b/koans/AboutHigherOrderFunctions.js index 2fc64e490..c45b24a0e 100644 --- a/koans/AboutHigherOrderFunctions.js +++ b/koans/AboutHigherOrderFunctions.js @@ -27,7 +27,12 @@ describe("About Higher Order Functions", function () { it("should use 'reduce' to update the same result on each iteration", function () { var numbers = [1, 2, 3]; var reduction = _(numbers).reduce( - function(/* result from last call */ memo, /* current */ x) { return memo + x }, /* initial */ 0); + function(memo, x) { + //note: memo is the result from last call, and x is the current number + return memo + x; + }, + /* initial */ 0 + ); expect(reduction).toBe(FILL_ME_IN); expect(numbers).toEqual(FILL_ME_IN); @@ -67,23 +72,23 @@ describe("About Higher Order Functions", function () { }); it("should use range to generate an array", function() { - expect(_.range(3)).toEqual(FILL_ME_IN); - expect(_.range(1, 4)).toEqual(FILL_ME_IN); - expect(_.range(0, -4, -1)).toEqual(FILL_ME_IN); + expect(_.range(3)).toEqual(FILL_ME_IN); + expect(_.range(1, 4)).toEqual(FILL_ME_IN); + expect(_.range(0, -4, -1)).toEqual(FILL_ME_IN); }); it("should use flatten to make nested arrays easy to work with", function() { - expect(_([ [1, 2], [3, 4] ]).flatten()).toEqual(FILL_ME_IN); + expect(_([ [1, 2], [3, 4] ]).flatten()).toEqual(FILL_ME_IN); }); it("should use chain() ... .value() to use multiple higher order functions", function() { - var result = _([ [0, 1], 2 ]).chain() - .flatten() - .map(function(x) { return x+1 } ) - .reduce(function (sum, x) { return sum + x }) - .value(); + var result = _([ [0, 1], 2 ]).chain() + .flatten() + .map(function(x) { return x+1 } ) + .reduce(function (sum, x) { return sum + x }) + .value(); - expect(result).toEqual(FILL_ME_IN); + expect(result).toEqual(FILL_ME_IN); }); }); diff --git a/koans/AboutInheritance.js b/koans/AboutInheritance.js index 7e305a711..1646d8310 100644 --- a/koans/AboutInheritance.js +++ b/koans/AboutInheritance.js @@ -21,7 +21,7 @@ SwedishChef.prototype = new Muppet(); describe("About inheritance", function() { beforeEach(function(){ this.muppet = new Muppet(2, "coding"); - this.swedishChef = new SwedishChef(2, "cooking", "chillin"); + this.swedishChef = new SwedishChef(2, "cooking", "chillin"); }); it("should be able to call a method on the derived object", function() { @@ -60,10 +60,14 @@ function Gonzo(age, hobby, trick) { //no longer need to call the Muppet (base type) constructor Gonzo.prototype = Muppet.prototype.beget(); +//note: if you're wondering how this line affects the below tests, the answer is that it doesn't. +//however, it does do something interesting -- it makes this work: +// var g = new Gonzo(...); +// g instanceOf Muppet //true describe("About Crockford's inheritance improvement", function() { beforeEach(function(){ - this.gonzo = new Gonzo(3, "daredevil performer", "eat a tire"); + this.gonzo = new Gonzo(3, "daredevil performer", "eat a tire"); }); it("should be able to call a method on the derived object", function() { diff --git a/koans/AboutObjects.js b/koans/AboutObjects.js index eac2b7504..374944e80 100644 --- a/koans/AboutObjects.js +++ b/koans/AboutObjects.js @@ -87,23 +87,23 @@ describe("About Objects", function () { it("should use prototype to add to all objects", function () { - function Circle(radius) - { - this.radius = radius; - } - - var simpleCircle = new Circle(10); - var colouredCircle = new Circle(5); - colouredCircle.colour = "red"; - - expect(simpleCircle.colour).toBe(FILL_ME_IN); - expect(colouredCircle.colour).toBe(FILL_ME_IN); - - Circle.prototype.describe = function () { - return "This circle has a radius of: " + this.radius; - }; + function Circle(radius) + { + this.radius = radius; + } + + var simpleCircle = new Circle(10); + var colouredCircle = new Circle(5); + colouredCircle.colour = "red"; - expect(simpleCircle.describe()).toBe(FILL_ME_IN); - expect(colouredCircle.describe()).toBe(FILL_ME_IN); + expect(simpleCircle.colour).toBe(FILL_ME_IN); + expect(colouredCircle.colour).toBe(FILL_ME_IN); + + Circle.prototype.describe = function () { + return "This circle has a radius of: " + this.radius; + }; + + expect(simpleCircle.describe()).toBe(FILL_ME_IN); + expect(colouredCircle.describe()).toBe(FILL_ME_IN); }); });