Skip to content
Open

Karma #172

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d48acf4
1st karma solved
M-RAY47 Jan 26, 2022
90d7bc2
Solved 2nd Karma
M-RAY47 Jan 26, 2022
dad0c16
solved 3rd and 4th karma
M-RAY47 Jan 26, 2022
123d303
solved 5-6 Karma
M-RAY47 Jan 26, 2022
e011b2c
solved 7-8 karma
M-RAY47 Jan 26, 2022
7b6422d
solved 9 karma
M-RAY47 Jan 27, 2022
55a3fee
solved 10th karma
M-RAY47 Jan 27, 2022
8b9fefa
array push and pop
M-RAY47 Jun 1, 2022
c497024
solved question 10th array push and pop
M-RAY47 Jun 1, 2022
6a13448
solved question 11th
M-RAY47 Jun 2, 2022
de61ace
solved question 11th
M-RAY47 Jun 2, 2022
6d5dbc2
solved question 11th
M-RAY47 Jun 2, 2022
ccf1aca
solved question 11th
M-RAY47 Jun 3, 2022
66d2ad4
finished aboout array karma
M-RAY47 Jun 3, 2022
45a18e7
karma about functions 1st question
M-RAY47 Jun 4, 2022
ac4f0f0
karma about functions 2nd question
M-RAY47 Jun 4, 2022
521d024
karma about functions 3rd question internal var override outer var
M-RAY47 Jun 5, 2022
c09ebb4
karma about functions 3rd question internal var override outer var
M-RAY47 Jun 5, 2022
4c68d76
karma about functions 4th question internal var override outer var
M-RAY47 Jun 5, 2022
e2ef8fd
karma about functions lexical scoping
M-RAY47 Jun 6, 2022
3ab5a34
karma about functions lexical scoping returning function
M-RAY47 Jun 6, 2022
bbdc09b
karma about functions lexical scoping returning first argument
M-RAY47 Jun 6, 2022
0a45014
karma about functions lexical scoping returning undefined argument if…
M-RAY47 Jun 7, 2022
0be63ae
karma about functions returning all arguments
M-RAY47 Jun 7, 2022
2c80e7c
karma about functions take a function as params
M-RAY47 Jun 8, 2022
c309081
karma about functions it should pass function as value
M-RAY47 Jun 8, 2022
556dada
About Objects collections propertieses
M-RAY47 Jun 9, 2022
0057f46
About Objects it should confirm properties are case sensitive
M-RAY47 Jun 9, 2022
d0d9fb7
About Objects it should confirm properties are case sensitive
M-RAY47 Jun 9, 2022
3ddd880
About Objects, functions acting like methods
M-RAY47 Jun 10, 2022
d4acffc
About Objects, it should confirm that a function is attached to an ob…
M-RAY47 Jun 10, 2022
b30ac2c
About Objects, it should confirm that a function is attached to an ob…
M-RAY47 Jun 10, 2022
4c77056
About Objects, considering in key of th object
M-RAY47 Jun 10, 2022
f9c8ee8
About Objects, considering in value in Object
M-RAY47 Jun 12, 2022
161c47b
About Objects, considering in value in Object
M-RAY47 Jun 12, 2022
5b37b53
About Objects, considering in value in Object
M-RAY47 Jun 12, 2022
43f4ee0
About Objects, deleting key and value from Object
M-RAY47 Jun 13, 2022
853f55b
About Objects, using prototype to add value to Object
M-RAY47 Jun 13, 2022
b4b3657
About Objects, using prototype to add value to Object
M-RAY47 Jun 13, 2022
e12e2a8
About Objects, using prototype to add value to Object
M-RAY47 Jun 14, 2022
35daad2
About Objects, using prototype to add value to Object
M-RAY47 Jun 14, 2022
7b26756
About Objects, using prototype to add value to Object
M-RAY47 Jun 14, 2022
7e9f541
About Mutability, expect Object props to be public and mutable
M-RAY47 Jun 15, 2022
6e2ff5e
About Mutability, expect Object constructor props to be public and mu…
M-RAY47 Jun 15, 2022
cb957e9
About Mutability, expect Object constructor props to be public and mu…
M-RAY47 Jun 15, 2022
b0f202c
About Mutability, expect Object constructor props to be public and mu…
M-RAY47 Jun 16, 2022
5704211
About Mutability, it should know variables inside constructor and con…
M-RAY47 Jun 16, 2022
1496bea
About Mutability, it should know variables inside constructor and con…
M-RAY47 Jun 16, 2022
a019f0d
About Mutability, it should know variables inside constructor and con…
M-RAY47 Jun 16, 2022
7abb1d9
About Mutability, it should know variables inside constructor and con…
M-RAY47 Jun 17, 2022
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
64 changes: 32 additions & 32 deletions koans/AboutArrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,56 @@ 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))=== typeof(FILL_ME_IN); //A mistake? - http://javascript.crockford.com/remedial.html
expect(emptyArray.length == FILL_ME_IN);

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] == FILL_ME_IN);
expect(multiTypeArray[2] === FILL_ME_IN);
expect(multiTypeArray[3]() == FILL_ME_IN);
expect(multiTypeArray[4].value1 == FILL_ME_IN);
expect(multiTypeArray[4]["value2"] == FILL_ME_IN);
expect(multiTypeArray[5][0] == FILL_ME_IN);
});

it("should understand array literals", function () {
var array = [];
expect(array).toEqual([]);
expect(array === []);

array[0] = 1;
expect(array).toEqual([1]);
expect(array = [1]);

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

array.push(3);
expect(array).toEqual(FILL_ME_IN);
expect(array == FILL_ME_IN);
});

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

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

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

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

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)) == (FILL_ME_IN);
expect(array.slice(0, 2)) == (FILL_ME_IN);
expect(array.slice(2, 2)) == (FILL_ME_IN);
expect(array.slice(2, 20)) == (FILL_ME_IN);
expect(array.slice(3, 0)) == (FILL_ME_IN);
expect(array.slice(3, 100)) === (FILL_ME_IN);
expect(array.slice(5, 1)) === (FILL_ME_IN);
});

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]) === (FILL_ME_IN);

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

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

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]);
});
});
12 changes: 6 additions & 6 deletions koans/AboutExpects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ describe('About Expects', function() {
// We shall contemplate truth by testing reality, via spec expectations.
it('should expect true', function() {

// Your journey begins here: Replace the word false with true
expect(false).toBeTruthy();
// Your journey begins here: Replace the word false with true
expect(true).toBeTruthy();
});

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

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

// Some ways of asserting equality are better than others.
Expand All @@ -21,7 +21,7 @@ describe('About Expects', function() {
var actualValue = 1 + 1;

// toEqual() compares using common sense equality.
expect(actualValue).toEqual(expectedValue);
expect(actualValue == expectedValue);
});

// Sometimes you need to be precise about what you "type."
Expand All @@ -30,11 +30,11 @@ describe('About Expects', function() {
var actualValue = (1 + 1).toString();

// toBe() will always use === to compare.
expect(actualValue).toBe(expectedValue);
expect(actualValue === expectedValue);
});

// 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 === FILL_ME_IN);
});
});
22 changes: 11 additions & 11 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 @@ -52,7 +52,7 @@ describe("About Functions", function() {
var mysteryFunction3 = makeMysteryFunction(3);
var mysteryFunction5 = makeMysteryFunction(5);

expect(mysteryFunction3(10) + mysteryFunction5(5)).toBe(FILL_ME_IN);
expect(mysteryFunction3(10) + mysteryFunction5(5)).toBe(23);
});

it("should allow extra function arguments", function () {
Expand All @@ -61,13 +61,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 @@ -77,7 +77,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 @@ -91,10 +91,10 @@ 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!');

});
});
16 changes: 8 additions & 8 deletions koans/AboutMutability.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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');
});

});
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(megalomaniac.mastermind).toBe(FILL_ME_IN);
expect(megalomaniac.mastermind).toBe('Joker');
});

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

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

var battleCry = megalomaniac.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(megalomaniac.calculateAge()).toBe(FILL_ME_IN);
expect(currentYear).toBe(2022);
expect(megalomaniac.calculateAge()).toBe(52);
});

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

var hasBomb = "theBomb" in megalomaniac;

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

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

var hasDetonator = "theDetonator" in megalomaniac;

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

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

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

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

delete megalomaniac.henchman;
expect("henchman" in megalomaniac).toBe(FILL_ME_IN);
expect("henchman" in megalomaniac).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');
});
});