Skip to content

Commit

Permalink
whitespace and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shawndrost committed Nov 25, 2012
1 parent d85a859 commit d04436d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion KoansRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
</script>

</body>
Expand Down
2 changes: 1 addition & 1 deletion koans/AboutArrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 16 additions & 11 deletions koans/AboutHigherOrderFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});

});
Expand Down
8 changes: 6 additions & 2 deletions koans/AboutInheritance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
34 changes: 17 additions & 17 deletions koans/AboutObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit d04436d

Please sign in to comment.