Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment Complete #38

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
93eb0e0
Replace false to true
yosef604 Oct 12, 2020
4f6f188
Assaigning expectedValue = 2
yosef604 Oct 12, 2020
52d07c3
assaigning expectValue = '2'
yosef604 Oct 12, 2020
04a6860
filling .toEquqlin 2
yosef604 Oct 12, 2020
3251cd7
Filling .toBe() in 'object'
yosef604 Oct 12, 2020
a5c7fd1
Filling .toBe() in 0
yosef604 Oct 12, 2020
254ce44
filling .toBe() in 0
yosef604 Oct 12, 2020
cf91c59
Filling .toBe() in 'two'
yosef604 Oct 12, 2020
eca25fa
Filling to
yosef604 Oct 12, 2020
f8f8766
Filling .toBe() with 4
yosef604 Oct 12, 2020
b191fc7
Filling .toBe() with 5
yosef604 Oct 12, 2020
1e27edd
Filling .toBe() with 6
yosef604 Oct 12, 2020
49df79c
filling the array with 2
yosef604 Oct 12, 2020
e3728a5
Filling toEqual() with [1, 2, 3]
yosef604 Oct 12, 2020
6a68817
Filling .toBe() with 4
yosef604 Oct 12, 2020
97e9704
Filling .toBe() with 6
yosef604 Oct 12, 2020
af68836
Filling .toBe() with 10
yosef604 Oct 12, 2020
f3196da
Filling .toBe() with 5
yosef604 Oct 12, 2020
4775b42
result = 'peanut'
yosef604 Oct 12, 2020
f1afca8
result = ['peanut', 'butter']
yosef604 Oct 12, 2020
7ea8c64
result = ['and', 'jely']
yosef604 Oct 12, 2020
0eb826c
result = []
yosef604 Oct 12, 2020
19ecfed
result = ['and', 'jelly']
yosef604 Oct 12, 2020
42b82f8
result = []
yosef604 Oct 12, 2020
0cab7c0
result = ['jelly']
yosef604 Oct 12, 2020
8cdf9f9
result = []
yosef604 Oct 12, 2020
707c6e4
Filling .toBe() with 'changed in function'
yosef604 Oct 12, 2020
10e867f
Filling .toBe() with 'changed in assignedArray'
yosef604 Oct 12, 2020
3c7be69
Filling .toBe() with 'three'
yosef604 Oct 12, 2020
e438401
result = [1, 2, 3]
yosef604 Oct 12, 2020
5213231
popedValue = 3
yosef604 Oct 12, 2020
4dee15e
after poping, array = [1, 2]
yosef604 Oct 12, 2020
5db8b5b
after unshifting, array = [3, 1, 2]
yosef604 Oct 12, 2020
a7b8bad
shiftedValue = 3
yosef604 Oct 12, 2020
72e725b
after shifting, array = [1, 2]
yosef604 Oct 12, 2020
202fea7
Passing all tests
yosef604 Oct 13, 2020
37378eb
Passing all tests
yosef604 Oct 13, 2020
2c6cf65
Assaigment complete
yosef604 Oct 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion koans/AboutApplyingWhatWeHaveLearnt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("About Applying What We Have Learnt", function() {
{ name: "Blue Moon", ingredients: ["blue cheese", "garlic", "walnuts"], containsNuts: true },
{ name: "Taste Of Athens", ingredients: ["spinach", "kalamata olives", "sesame seeds"], containsNuts: true }
];
});
});

/*********************************************************************************/

Expand Down
60 changes: 30 additions & 30 deletions koans/AboutArrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ describe("About Arrays", function() {
//We shall contemplate truth by testing reality, via spec expectations.
it("should create arrays", function() {
var emptyArray = [];
expect(typeof(emptyArray)).toBe(FILL_ME_IN); //A mistake? - http:javascript.crockford.com/remedial.html
expect(emptyArray.length).toBe(FILL_ME_IN);
expect(typeof(emptyArray)).toBe('object'); //A mistake? - http:javascript.crockford.com/remedial.html
expect(emptyArray.length).toBe(0);

var multiTypeArray = [0, 1, "two", function () { return 3; }, {value1: 4, value2: 5}, [6, 7]];
expect(multiTypeArray[0]).toBe(FILL_ME_IN);
expect(multiTypeArray[2]).toBe(FILL_ME_IN);
expect(multiTypeArray[3]()).toBe(FILL_ME_IN);
expect(multiTypeArray[4].value1).toBe(FILL_ME_IN);
expect(multiTypeArray[4]["value2"]).toBe(FILL_ME_IN);
expect(multiTypeArray[5][0]).toBe(FILL_ME_IN);
expect(multiTypeArray[0]).toBe(0);
expect(multiTypeArray[2]).toBe('two');
expect(multiTypeArray[3]()).toBe(3);
expect(multiTypeArray[4].value1).toBe(4);
expect(multiTypeArray[4]["value2"]).toBe(5);
expect(multiTypeArray[5][0]).toBe(6);
});

it("should understand array literals", function () {
Expand All @@ -23,36 +23,36 @@ describe("About Arrays", function() {
expect(array).toEqual([1]);

array[1] = 2;
expect(array).toEqual([1, FILL_ME_IN]);
expect(array).toEqual([1, 2]);

array.push(3);
expect(array).toEqual(FILL_ME_IN);
expect(array).toEqual([1, 2, 3]);
});

it("should understand array length", function () {
var fourNumberArray = [1, 2, 3, 4];

expect(fourNumberArray.length).toBe(FILL_ME_IN);
expect(fourNumberArray.length).toBe(4);
fourNumberArray.push(5, 6);
expect(fourNumberArray.length).toBe(FILL_ME_IN);
expect(fourNumberArray.length).toBe(6);

var tenEmptyElementArray = new Array(10);
expect(tenEmptyElementArray.length).toBe(FILL_ME_IN);
expect(tenEmptyElementArray.length).toBe(10);

tenEmptyElementArray.length = 5;
expect(tenEmptyElementArray.length).toBe(FILL_ME_IN);
expect(tenEmptyElementArray.length).toBe(5);
});

it("should slice arrays", function () {
var array = ["peanut", "butter", "and", "jelly"];

expect(array.slice(0, 1)).toEqual(FILL_ME_IN);
expect(array.slice(0, 2)).toEqual(FILL_ME_IN);
expect(array.slice(2, 2)).toEqual(FILL_ME_IN);
expect(array.slice(2, 20)).toEqual(FILL_ME_IN);
expect(array.slice(3, 0)).toEqual(FILL_ME_IN);
expect(array.slice(3, 100)).toEqual(FILL_ME_IN);
expect(array.slice(5, 1)).toEqual(FILL_ME_IN);
expect(array.slice(0, 1)).toEqual(['peanut']);
expect(array.slice(0, 2)).toEqual(['peanut', 'butter']);
expect(array.slice(2, 2)).toEqual([]);
expect(array.slice(2, 20)).toEqual(['and', 'jelly']);
expect(array.slice(3, 0)).toEqual([]);
expect(array.slice(3, 100)).toEqual(['jelly']);
expect(array.slice(5, 1)).toEqual([]);
});

it("should know array references", function () {
Expand All @@ -62,36 +62,36 @@ describe("About Arrays", function() {
refArray[1] = "changed in function";
}
passedByReference(array);
expect(array[1]).toBe(FILL_ME_IN);
expect(array[1]).toBe("changed in function");

var assignedArray = array;
assignedArray[5] = "changed in assignedArray";
expect(array[5]).toBe(FILL_ME_IN);
expect(array[5]).toBe("changed in assignedArray");

var copyOfArray = array.slice();
copyOfArray[3] = "changed in copyOfArray";
expect(array[3]).toBe(FILL_ME_IN);
expect(array[3]).toBe('three');
});

it("should push and pop", function () {
var array = [1, 2];
array.push(3);

expect(array).toEqual(FILL_ME_IN);
expect(array).toEqual([1, 2, 3]);

var poppedValue = array.pop();
expect(poppedValue).toBe(FILL_ME_IN);
expect(array).toEqual(FILL_ME_IN);
expect(poppedValue).toBe(3);
expect(array).toEqual([1, 2]);
});

it("should know about shifting arrays", function () {
var array = [1, 2];

array.unshift(3);
expect(array).toEqual(FILL_ME_IN);
expect(array).toEqual([3, 1, 2]);

var shiftedValue = array.shift();
expect(shiftedValue).toEqual(FILL_ME_IN);
expect(array).toEqual(FILL_ME_IN);
expect(shiftedValue).toEqual(3);
expect(array).toEqual([1, 2]);
});
});
10 changes: 5 additions & 5 deletions koans/AboutExpects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ describe("About Expects", function() {

//We shall contemplate truth by testing reality, via spec expectations.
it("should expect true", function() {
expect(false).toBeTruthy(); //This should be true
expect(true).toBeTruthy(); //This should be true
});

//To understand reality, we must compare our expectations against reality.
it("should expect equality", function () {
var expectedValue = FILL_ME_IN;
var expectedValue = 2;
var actualValue = 1 + 1;

expect(actualValue === expectedValue).toBeTruthy();
});

//Some ways of asserting equality are better than others.
it("should assert equality a better way", function () {
var expectedValue = FILL_ME_IN;
var expectedValue = 2;
var actualValue = 1 + 1;

// toEqual() compares using common sense equality.
Expand All @@ -24,7 +24,7 @@ describe("About Expects", function() {

//Sometimes you need to be really exact about what you "type".
it("should assert equality with ===", function () {
var expectedValue = FILL_ME_IN;
var expectedValue = '2';
var actualValue = (1 + 1).toString();

// toBe() will always use === to compare.
Expand All @@ -33,6 +33,6 @@ describe("About Expects", function() {

//Sometimes we will ask you to fill in the values.
it("should have filled in values", function () {
expect(1 + 1).toEqual(FILL_ME_IN);
expect(1 + 1).toEqual(2);
});
});
29 changes: 16 additions & 13 deletions koans/AboutFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("About Functions", function() {
return a + b;
}

expect(add(1, 2)).toBe(FILL_ME_IN);
expect(add(1, 2)).toBe(3);
});

it("should know internal variables override outer variables", function () {
Expand All @@ -21,9 +21,9 @@ describe("About Functions", function() {
return message;
}

expect(getMessage()).toBe(FILL_ME_IN);
expect(overrideMessage()).toBe(FILL_ME_IN);
expect(message).toBe(FILL_ME_IN);
expect(getMessage()).toBe('Outer');
expect(overrideMessage()).toBe('Inner');
expect(message).toBe('Outer');
});

it("should have lexical scoping", function () {
Expand All @@ -35,7 +35,7 @@ describe("About Functions", function() {
}
return childfunction();
}
expect(parentfunction()).toBe(FILL_ME_IN);
expect(parentfunction()).toBe('local');
});

it("should use lexical scoping to synthesise functions", function () {
Expand All @@ -49,7 +49,7 @@ describe("About Functions", function() {
var increaseBy3 = makeIncreaseByFunction(3);
var increaseBy5 = makeIncreaseByFunction(5);

expect(increaseBy3(10) + increaseBy5(10)).toBe(FILL_ME_IN);
expect(increaseBy3(10) + increaseBy5(10)).toBe(28);
});

it("should allow extra function arguments", function () {
Expand All @@ -58,13 +58,13 @@ describe("About Functions", function() {
return firstArg;
}

expect(returnFirstArg("first", "second", "third")).toBe(FILL_ME_IN);
expect(returnFirstArg("first", "second", "third")).toBe('first');

function returnSecondArg(firstArg, secondArg) {
return secondArg;
}

expect(returnSecondArg("only give first arg")).toBe(FILL_ME_IN);
expect(returnSecondArg("only give first arg")).toBe(undefined);

function returnAllArgs() {
var argsArray = [];
Expand All @@ -74,7 +74,7 @@ describe("About Functions", function() {
return argsArray.join(",");
}

expect(returnAllArgs("first", "second", "third")).toBe(FILL_ME_IN);
expect(returnAllArgs("first", "second", "third")).toBe("first,second,third");
});

it("should pass functions as values", function () {
Expand All @@ -88,21 +88,24 @@ describe("About Functions", function() {
};

var praiseSinger = { givePraise: appendRules };
expect(praiseSinger.givePraise("John")).toBe(FILL_ME_IN);
expect(praiseSinger.givePraise("John")).toBe('John rules!');

praiseSinger.givePraise = appendDoubleRules;
expect(praiseSinger.givePraise("Mary")).toBe(FILL_ME_IN);
expect(praiseSinger.givePraise("Mary")).toBe('Mary totally rules!');

});

it("should use function body as a string", function () {
var add = new Function("a", "b", "return a + b;");
expect(add(1, 2)).toBe(FILL_ME_IN);
expect(add(1, 2)).toBe(3);

var multiply = function (a, b) {
//An internal comment
return a * b;
};
expect(multiply.toString()).toBe(FILL_ME_IN);
expect(multiply.toString()).toBe(`function (a, b) {
//An internal comment
return a * b;
}`);
});
});
30 changes: 15 additions & 15 deletions koans/AboutObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ describe("About Objects", function () {
});

it("should confirm objects are collections of properties", function () {
expect(meglomaniac.mastermind).toBe(FILL_ME_IN);
expect(meglomaniac.mastermind).toBe("Joker");
});

it("should confirm that properties are case sensitive", function () {
expect(meglomaniac.henchwoman).toBe(FILL_ME_IN);
expect(meglomaniac.henchWoman).toBe(FILL_ME_IN);
expect(meglomaniac.henchwoman).toBe('Harley');
expect(meglomaniac.henchWoman).toBe(undefined);
});
});

Expand All @@ -29,7 +29,7 @@ describe("About Objects", function () {
};

var battleCry = meglomaniac.battleCry(4);
expect(FILL_ME_IN).toMatch(battleCry);
expect('They are Pinky and the Brain Brain Brain Brain').toMatch(battleCry);
});

it("should confirm that when a function is attached to an object, 'this' refers to the object", function () {
Expand All @@ -44,8 +44,8 @@ describe("About Objects", function () {
}
};

expect(currentYear).toBe(FILL_ME_IN);
expect(meglomaniac.calculateAge()).toBe(FILL_ME_IN);
expect(currentYear).toBe(2020);
expect(meglomaniac.calculateAge()).toBe(50);
});

describe("'in' keyword", function () {
Expand All @@ -62,27 +62,27 @@ describe("About Objects", function () {

var hasBomb = "theBomb" in meglomaniac;

expect(hasBomb).toBe(FILL_ME_IN);
expect(hasBomb).toBe(true);
});

it("should not have the detonator however", function () {

var hasDetonator = "theDetonator" in meglomaniac;

expect(hasDetonator).toBe(FILL_ME_IN);
expect(hasDetonator).toBe(false);
});
});

it("should know that properties can be added and deleted", function () {
var meglomaniac = { mastermind : "Agent Smith", henchman: "Agent Smith" };

expect("secretary" in meglomaniac).toBe(FILL_ME_IN);
expect("secretary" in meglomaniac).toBe(false);

meglomaniac.secretary = "Agent Smith";
expect("secretary" in meglomaniac).toBe(FILL_ME_IN);
expect("secretary" in meglomaniac).toBe(true);

delete meglomaniac.henchman;
expect("henchman" in meglomaniac).toBe(FILL_ME_IN);
expect("henchman" in meglomaniac).toBe(false);
});


Expand All @@ -96,14 +96,14 @@ describe("About Objects", function () {
var colouredCircle = new Circle(5);
colouredCircle.colour = "red";

expect(simpleCircle.colour).toBe(FILL_ME_IN);
expect(colouredCircle.colour).toBe(FILL_ME_IN);
expect(simpleCircle.colour).toBe(undefined);
expect(colouredCircle.colour).toBe('red');

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);
expect(simpleCircle.describe()).toBe("This circle has a radius of: 10");
expect(colouredCircle.describe()).toBe("This circle has a radius of: 5");
});
});