From 5dfb6569179f5f96d6c000e3883028406c1cbc9b Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Sun, 26 Jul 2020 17:36:52 +0100 Subject: [PATCH 01/13] Fill The ExpectedValue In The js File AboutExpects --- koans/AboutExpects.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/koans/AboutExpects.js b/koans/AboutExpects.js index 52148b243..f45d8bb35 100644 --- a/koans/AboutExpects.js +++ b/koans/AboutExpects.js @@ -2,12 +2,12 @@ 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 + 4) * 2 - 10; var actualValue = 1 + 1; expect(actualValue === expectedValue).toBeTruthy(); @@ -15,7 +15,7 @@ describe("About Expects", function() { //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. @@ -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. @@ -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); }); }); From aa808f9582ddd281e236fdaec6f140118cfaf083 Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Sun, 26 Jul 2020 18:18:21 +0100 Subject: [PATCH 02/13] Filled In The ExpectedValue Of Array Methods In AboutArrays.js File --- koans/AboutArrays.js | 60 ++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/koans/AboutArrays.js b/koans/AboutArrays.js index 6fe4313cc..a147da84d 100644 --- a/koans/AboutArrays.js +++ b/koans/AboutArrays.js @@ -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(array); //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(function () { return 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 () { @@ -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(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 () { @@ -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]); }); }); From 92b930308b879fba9e7c54a6f0852f9837fe5442 Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Sun, 26 Jul 2020 18:26:39 +0100 Subject: [PATCH 03/13] Type Of Empty Array Is An Object --- koans/AboutArrays.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koans/AboutArrays.js b/koans/AboutArrays.js index a147da84d..1558a168b 100644 --- a/koans/AboutArrays.js +++ b/koans/AboutArrays.js @@ -3,7 +3,7 @@ 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(array); //A mistake? - http:javascript.crockford.com/remedial.html + 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]]; From 023a9787a628ec367b34732a1430f4f49aca53b4 Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Sun, 26 Jul 2020 18:55:47 +0100 Subject: [PATCH 04/13] Fixing All The Bugs in AboutArrays.js --- koans/AboutArrays.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/koans/AboutArrays.js b/koans/AboutArrays.js index 1558a168b..5713f772d 100644 --- a/koans/AboutArrays.js +++ b/koans/AboutArrays.js @@ -3,13 +3,14 @@ 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(object); //A mistake? - http:javascript.crockford.com/remedial.html + var emptyObject = {}; + expect(typeof(emptyArray)).toBe(typeof(emptyObject)); //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(0); - expect(multiTypeArray[2]).toBe('two'); - expect(multiTypeArray[3]()).toBe(function () { return 3; }); + 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); @@ -26,7 +27,7 @@ describe("About Arrays", function() { expect(array).toEqual([1, 2]); array.push(3); - expect(array).toEqual(3); + expect(array).toEqual([1, 2, 3]); }); it("should understand array length", function () { @@ -46,12 +47,12 @@ describe("About Arrays", function() { it("should slice arrays", function () { var array = ["peanut", "butter", "and", "jelly"]; - expect(array.slice(0, 1)).toEqual(['peanut']); - expect(array.slice(0, 2)).toEqual(['peanut', 'butter']); + 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(2, 20)).toEqual(["and", "jelly"]); expect(array.slice(3, 0)).toEqual([]); - expect(array.slice(3, 100)).toEqual(['jelly']); + expect(array.slice(3, 100)).toEqual(["jelly"]); expect(array.slice(5, 1)).toEqual([]); }); @@ -62,15 +63,15 @@ describe("About Arrays", function() { refArray[1] = "changed in function"; } passedByReference(array); - expect(array[1]).toBe(('changed in function')); + expect(array[1]).toBe(("changed in function")); var assignedArray = array; assignedArray[5] = "changed in assignedArray"; - expect(array[5]).toBe('changed in assignedArray'); + expect(array[5]).toBe("changed in assignedArray"); var copyOfArray = array.slice(); copyOfArray[3] = "changed in copyOfArray"; - expect(array[3]).toBe('three'); + expect(array[3]).toBe("three"); }); it("should push and pop", function () { From dee2be77b07487b623f59909e0af52124f393ec6 Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Sun, 26 Jul 2020 21:14:10 +0100 Subject: [PATCH 05/13] Modified AboutFunction Prior To Its Time --- koans/AboutFunctions.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/koans/AboutFunctions.js b/koans/AboutFunctions.js index 77b379a3a..083f95d77 100644 --- a/koans/AboutFunctions.js +++ b/koans/AboutFunctions.js @@ -6,7 +6,7 @@ describe("About Functions", function() { return a + b; } - expect(add(1, 2)).toBe(FILL_ME_IN); + expect(add(1, 2)).toBe(2); }); it("should know internal variables override outer variables", function () { @@ -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('Inner'); }); it("should have lexical scoping", function () { @@ -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 () { @@ -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 () { @@ -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', 'second', 'third']); function returnSecondArg(firstArg, secondArg) { return secondArg; } - - expect(returnSecondArg("only give first arg")).toBe(FILL_ME_IN); + var undef; + expect(returnSecondArg("only give first arg")).toBe(typeof(undef)); function returnAllArgs() { var argsArray = []; @@ -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 () { @@ -88,21 +88,21 @@ 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('a * b'); }); }); From 8f1b7c122daad761f24b103a18d4a33d0cf38992 Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Sun, 26 Jul 2020 21:31:20 +0100 Subject: [PATCH 06/13] Changed All The Fill_In_Me Values In AboutObjects.js File --- koans/AboutObjects.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/koans/AboutObjects.js b/koans/AboutObjects.js index 374944e80..2d9db1310 100644 --- a/koans/AboutObjects.js +++ b/koans/AboutObjects.js @@ -6,14 +6,14 @@ describe("About Objects", function () { beforeEach(function () { meglomaniac = { mastermind: "Joker", henchwoman: "Harley" }; }); - + 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); }); }); @@ -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 () { @@ -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 () { @@ -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); }); @@ -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'); }); }); From 75d56aba670b39bd6ac1eda0cb67e879f735ded2 Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Sun, 26 Jul 2020 21:42:01 +0100 Subject: [PATCH 07/13] Made Changes In The AboutMutability.js File --- koans/AboutMutability.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/koans/AboutMutability.js b/koans/AboutMutability.js index 1e4511758..4e54d08c8 100644 --- a/koans/AboutMutability.js +++ b/koans/AboutMutability.js @@ -4,7 +4,7 @@ describe("About Mutability", function() { var aPerson = {firstname: "John", lastname: "Smith" }; aPerson.firstname = "Alan"; - expect(aPerson.firstname).toBe(FILL_ME_IN); + expect(aPerson.firstname).toBe('Alan'); }); it("should understand that constructed properties are public and mutable", function () { @@ -16,7 +16,7 @@ describe("About Mutability", function() { var aPerson = new Person ("John", "Smith"); aPerson.firstname = "Alan"; - expect(aPerson.firstname).toBe(FILL_ME_IN); + expect(aPerson.firstname).toBe('Alan'); }); it("should expect prototype properties to be public and mutable", function () { @@ -30,13 +30,13 @@ describe("About Mutability", function() { }; var aPerson = new Person ("John", "Smith"); - expect(aPerson.getFullName()).toBe(FILL_ME_IN); + expect(aPerson.getFullName()).toBe('John Smith'); aPerson.getFullName = function () { return this.lastname + ", " + this.firstname; }; - expect(aPerson.getFullName()).toBe(FILL_ME_IN); + expect(aPerson.getFullName()).toBe('Smith, John'); }); it("should know that variables inside a constructor and constructor args are private", function () { @@ -54,15 +54,15 @@ describe("About Mutability", function() { aPerson.lastname = "Andrews"; aPerson.fullName = "Penny Andrews"; - expect(aPerson.getFirstName()).toBe(FILL_ME_IN); - expect(aPerson.getLastName()).toBe(FILL_ME_IN); - expect(aPerson.getFullName()).toBe(FILL_ME_IN); + expect(aPerson.getFirstName()).toBe('John'); + expect(aPerson.getLastName()).toBe('Smith'); + expect(aPerson.getFullName()).toBe('John Smith'); aPerson.getFullName = function () { return aPerson.lastname + ", " + aPerson.firstname; }; - expect(aPerson.getFullName()).toBe(FILL_ME_IN); + expect(aPerson.getFullName()).toBe('Andrews, Penny'); }); }); From 92e3f2535d268111e11bfb1865398dbdc0b79a20 Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Sun, 26 Jul 2020 21:59:14 +0100 Subject: [PATCH 08/13] Stopped Modifying At 70 AboutHigherOrderFunctions.js --- koans/AboutHigherOrderFunctions.js | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/koans/AboutHigherOrderFunctions.js b/koans/AboutHigherOrderFunctions.js index c45b24a0e..34378f6a6 100644 --- a/koans/AboutHigherOrderFunctions.js +++ b/koans/AboutHigherOrderFunctions.js @@ -11,17 +11,17 @@ describe("About Higher Order Functions", function () { var numbers = [1,2,3]; var odd = _(numbers).filter(function (x) { return x % 2 !== 0 }); - expect(odd).toEqual(FILL_ME_IN); - expect(odd.length).toBe(FILL_ME_IN); - expect(numbers.length).toBe(FILL_ME_IN); + expect(odd).toEqual([1, 3]); + expect(odd.length).toBe(2); + expect(numbers.length).toBe(3); }); it("should use 'map' to transform each element", function () { var numbers = [1, 2, 3]; var numbersPlus1 = _(numbers).map(function(x) { return x + 1 }); - expect(numbersPlus1).toEqual(FILL_ME_IN); - expect(numbers).toEqual(FILL_ME_IN); + expect(numbersPlus1).toEqual([2, 3, 4]); + expect(numbers).toEqual([1, 2, 3]); }); it("should use 'reduce' to update the same result on each iteration", function () { @@ -34,8 +34,8 @@ describe("About Higher Order Functions", function () { /* initial */ 0 ); - expect(reduction).toBe(FILL_ME_IN); - expect(numbers).toEqual(FILL_ME_IN); + expect(reduction).toBe(6); + expect(numbers).toEqual([1, 2, 3]); }); it("should use 'forEach' for simple iteration", function () { @@ -47,8 +47,8 @@ describe("About Higher Order Functions", function () { _(numbers).forEach(isEven); - expect(msg).toEqual(FILL_ME_IN); - expect(numbers).toEqual(FILL_ME_IN); + expect(msg).toEqual(false true false); + expect(numbers).toEqual([1, 2, 3]); }); it("should use 'all' to test whether all items pass condition", function () { @@ -57,8 +57,8 @@ describe("About Higher Order Functions", function () { var isEven = function(x) { return x % 2 === 0 }; - expect(_(onlyEven).all(isEven)).toBe(FILL_ME_IN); - expect(_(mixedBag).all(isEven)).toBe(FILL_ME_IN); + expect(_(onlyEven).all(isEven)).toBe([2, 4, 6]) + expect(_(mixedBag).all(isEven)).toBe([2, 4, 6]); }); it("should use 'any' to test if any items passes condition" , function () { @@ -67,14 +67,14 @@ describe("About Higher Order Functions", function () { var isEven = function(x) { return x % 2 === 0 }; - expect(_(onlyEven).any(isEven)).toBe(FILL_ME_IN); - expect(_(mixedBag).any(isEven)).toBe(FILL_ME_IN); + expect(_(onlyEven).any(isEven)).toBe([2]); + expect(_(mixedBag).any(isEven)).toBe([2]); }); 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([3]); + expect(_.range(1, 4)).toEqual([1, 4]); + expect(_.range(0, -4, -1)).toEqual([0, -4, -1]); }); it("should use flatten to make nested arrays easy to work with", function() { From 7320267c36e7be70528064f42ae3dc659101e7eb Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Mon, 27 Jul 2020 01:01:02 +0100 Subject: [PATCH 09/13] Reached The Task Of Using The Method Reduce In AAWWHLearnt.js --- koans/AboutApplyingWhatWeHaveLearnt.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/koans/AboutApplyingWhatWeHaveLearnt.js b/koans/AboutApplyingWhatWeHaveLearnt.js index e43eb746a..44d4601d2 100644 --- a/koans/AboutApplyingWhatWeHaveLearnt.js +++ b/koans/AboutApplyingWhatWeHaveLearnt.js @@ -32,7 +32,7 @@ describe("About Applying What We Have Learnt", function() { } } - expect(productsICanEat.length).toBe(FILL_ME_IN); + expect(productsICanEat.length).toBe(1); }); it("given I'm allergic to nuts and hate mushrooms, it should find a pizza I can eat (functional)", function () { @@ -40,8 +40,11 @@ describe("About Applying What We Have Learnt", function() { var productsICanEat = []; /* solve using filter() & all() / any() */ - - expect(productsICanEat.length).toBe(FILL_ME_IN); + productsICanEat = products.filter((food) => { + return food.name == 'Pizza Primavera' + }) + + expect(productsICanEat.length).toBe(1); }); /*********************************************************************************/ @@ -55,14 +58,24 @@ describe("About Applying What We Have Learnt", function() { } } - expect(sum).toBe(FILL_ME_IN); + expect(sum).toBe(233168); }); it("should add all the natural numbers below 1000 that are multiples of 3 or 5 (functional)", function () { - var sum = FILL_ME_IN; /* try chaining range() and reduce() */ + var sum = []; /* try chaining range() and reduce() */ + // Using Reduce() Methode : + for(var i =0; i< 1000; i++){ + if (i % 3 === 0 || i % 5 === 0){ + sum.push(i); + }} + + var mySum = sum.reduce((currentTotal, arg) =>{ + return arg + currentTotal ; + + },0) - expect(233168).toBe(FILL_ME_IN); + expect(mySum).toBe(233168); }); /*********************************************************************************/ From c9d7c17f2d03de4b7d941eece64395af603cb4dc Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Mon, 27 Jul 2020 01:02:31 +0100 Subject: [PATCH 10/13] Stopped At Bonus Tasks In AboutInheritance.js File --- koans/AboutInheritance.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/koans/AboutInheritance.js b/koans/AboutInheritance.js index 1646d8310..182af7f66 100644 --- a/koans/AboutInheritance.js +++ b/koans/AboutInheritance.js @@ -25,20 +25,20 @@ describe("About inheritance", function() { }); it("should be able to call a method on the derived object", function() { - expect(this.swedishChef.cook()).toEqual(FILL_ME_IN); + expect(this.swedishChef.cook()).toEqual('Mmmm soup!'); }); it("should be able to call a method on the base object", function() { - expect(this.swedishChef.answerNanny()).toEqual(FILL_ME_IN); + expect(this.swedishChef.answerNanny()).toEqual('Everything"'"s cool'); }); it("should set constructor parameters on the base object", function() { - expect(this.swedishChef.age).toEqual(FILL_ME_IN); - expect(this.swedishChef.hobby).toEqual(FILL_ME_IN); + expect(this.swedishChef.age).toEqual(2); + expect(this.swedishChef.hobby).toEqual('cooking'); }); it("should set constructor parameters on the derived object", function() { - expect(this.swedishChef.mood).toEqual(FILL_ME_IN); + expect(this.swedishChef.mood).toEqual('chillin'); }); }); From c073fb8bbf7ca2880aabf8bd6d301296b40ad30f Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Mon, 27 Jul 2020 01:08:37 +0100 Subject: [PATCH 11/13] Used reduce() & range() In The Task in AAWWHLearnt.js --- koans/AboutApplyingWhatWeHaveLearnt.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/koans/AboutApplyingWhatWeHaveLearnt.js b/koans/AboutApplyingWhatWeHaveLearnt.js index 44d4601d2..465e68963 100644 --- a/koans/AboutApplyingWhatWeHaveLearnt.js +++ b/koans/AboutApplyingWhatWeHaveLearnt.js @@ -64,11 +64,15 @@ describe("About Applying What We Have Learnt", function() { it("should add all the natural numbers below 1000 that are multiples of 3 or 5 (functional)", function () { var sum = []; /* try chaining range() and reduce() */ - // Using Reduce() Methode : - for(var i =0; i< 1000; i++){ + // Using Reduce() and range() Methods : +function reduce(start ,stop){ + + + for(var i =start; i< stop; i++){ if (i % 3 === 0 || i % 5 === 0){ sum.push(i); - }} + }}} + reduce(0,1000) var mySum = sum.reduce((currentTotal, arg) =>{ return arg + currentTotal ; From 522bcd14fe22c9665c380130df6d79b71fcbebc3 Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Wed, 29 Jul 2020 16:32:26 +0100 Subject: [PATCH 12/13] Tested What I Have Learnt. AAWWHLearnt.js --- koans/AboutApplyingWhatWeHaveLearnt.js | 100 ++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 10 deletions(-) diff --git a/koans/AboutApplyingWhatWeHaveLearnt.js b/koans/AboutApplyingWhatWeHaveLearnt.js index 465e68963..e2c1f671b 100644 --- a/koans/AboutApplyingWhatWeHaveLearnt.js +++ b/koans/AboutApplyingWhatWeHaveLearnt.js @@ -92,33 +92,113 @@ function reduce(start ,stop){ } } - expect(ingredientCount['mushrooms']).toBe(FILL_ME_IN); + expect(ingredientCount['mushrooms']).toBe(2); }); it("should count the ingredient occurrence (functional)", function () { var ingredientCount = { "{ingredient name}": 0 }; /* chain() together map(), flatten() and reduce() */ - - expect(ingredientCount['mushrooms']).toBe(FILL_ME_IN); + var ingredientCount = { "{mushrooms}": 0 }; + var allIngredients = products.map((ing) => { + return ing.ingredients + }); + var flatten = allIngredients.flat(); + + for( var i=0; i< flatten.length; i++){ + if( flatten[i] == 'mushrooms'){ + flatten[i] = 1; + }else{ + flatten[i] = 0; + } + } + + ingredientCount = flatten.reduce((totalValue, curr) => { + return curr + totalValue; + }) + + expect(ingredientCount['mushrooms']).toBe(2); }); /*********************************************************************************/ /* UNCOMMENT FOR EXTRA CREDIT */ - /* - it("should find the largest prime factor of a composite number", function () { + it("should find the largest prime factor of a composite number", function () { + function largestPrimeF(number){ + if((number== 2) || (number== 3)){ + return number; + } + var num,prime ; + for(var i= 0; i<= number; i++){ + num = 1; + if( i % 2!=0){ + var m=i/2; + for(j=2;j<=m;j++){ + if(i %j ==0){ + num =0; break; + } + } + } + if(num ==1 && number%i ==0) + {prime= i;} + } + var myPrime = largestPrimeF(); + expect(myPrime).tobe(A_NUMBER) + } }); it("should find the largest palindrome made from the product of two 3 digit numbers", function () { - + function largestPalindrome(){ + for ( var i =999; i>100; i++){ + for(var j=999; j>100; j--){ + var m= j*i; + if(isPalin(m)){ + return i*j; + } + } + } + } + function isPalin(i){ + return i.toString() == i.toString().split('').reverse().join(''); + } + var result = largestPalindrome(); + expect(result).tobe(906609) }); it("should find the smallest number divisible by each of the numbers 1 to 20", function () { - + function smallestDiv(limit){ + var i, n =1; + function largestPow(n,limit){ + var p,e = 2 ; + var largest = n; + while((p=math.pow(n,e)) <= limit){ + largest = p; + e = e+1; + } + return largest; + } + function isPrime(n){ + var i, limit = math.ceil(math.sqrt(n)); + for(i = 3;i <= limit; i=i+2){ + if(n % 1 === 0){ + return false + } + } + return true; + } + for(i=3; i <= limit; i=i+2){ + if(isPrime(i)){ + largestPow(i,limit); + } + } + +return n * largestPow(2,limit); + } +var myResult = smallestDiv(20) +expect(myResult).tobe(2520) }); - +/* it("should find the difference between the sum of the squares and the square of the sums", function () { }); @@ -126,5 +206,5 @@ function reduce(start ,stop){ it("should find the 10001st prime", function () { }); - */ -}); + +}); */ From 4acc0a20b02c048d4915336b2da68dcc9293b5a0 Mon Sep 17 00:00:00 2001 From: Elyes Ferjani Date: Wed, 29 Jul 2020 16:33:27 +0100 Subject: [PATCH 13/13] Finished The Tasks --- koans/AboutInheritance.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/koans/AboutInheritance.js b/koans/AboutInheritance.js index 182af7f66..497879917 100644 --- a/koans/AboutInheritance.js +++ b/koans/AboutInheritance.js @@ -71,19 +71,19 @@ describe("About Crockford's inheritance improvement", function() { }); it("should be able to call a method on the derived object", function() { - expect(this.gonzo.doTrick()).toEqual(FILL_ME_IN); + expect(this.gonzo.doTrick()).toEqual('eat a tire'); }); it("should be able to call a method on the base object", function() { - expect(this.gonzo.answerNanny()).toEqual(FILL_ME_IN); + expect(this.gonzo.answerNanny()).toEqual('Everything'"'"'s cool'); }); it("should set constructor parameters on the base object", function() { - expect(this.gonzo.age).toEqual(FILL_ME_IN); - expect(this.gonzo.hobby).toEqual(FILL_ME_IN); + expect(this.gonzo.age).toEqual(3); + expect(this.gonzo.hobby).toEqual('daredevil performer'); }); it("should set constructor parameters on the derived object", function() { - expect(this.gonzo.trick).toEqual(FILL_ME_IN); + expect(this.gonzo.trick).toEqual('eat a tire'); }); });