mrdavidlaing / javascript-koans Goto Github PK
View Code? Open in Web Editor NEWKoans to learn Javascript
License: MIT License
Koans to learn Javascript
License: MIT License
it("should not have the detonator however", function () {
hasDetonator = "theDetonator" in meglomaniac;
expect(hasDetonator).toBe(FILL_ME_IN);
});
"theDetonator" property is missing in the object:
var meglomaniac;
beforeEach(function () {
meglomaniac = {
mastermind: "The Monarch",
henchwoman: "Dr Girlfriend",
theBomb: true
};
});
Is there a reason for including koans related to dojo? I don't understand what leaning dojo has to do with learning javascript. Can they be moved out to a separate repo called dojo-koans?
Using a more recent chain syntax, `_.chain(collection)`, will cause errors.
Koan 53 requires the original syntax of : `_(collection).chain`.
The more recent chain syntax was added more than 4 years ago,
and causes confusion when otherwise correct code produces errors.
Adding a note to koan 53 should remove this source of confusion
for users familiar with the newer `_.chain(collection)` syntax.
reference notes:
javascript-koans uses underscore v 1.1.6 from Apr 2011
newer chain syntax was added in v 1.2.3 on 30 Dec 2011 as fix #408
current underscore library is v 1.8.3
console.log(_.chain)
yields undefined in my instance. Other underscore methods are available.
In the file, AboutApplyingWhatWeHaveLeart.js
The following line:
expect(233168).toBe(FILL_ME_IN);
should be
expect(sum).toBe(233168);
There is nothing to fill in on this line. (I saw someone fill in with 233168, which is not the point!)
This would allow the test runner to be run in the ide and not just from a separate window
AboutObjects.js line 32 has an expected answer of "They are Pinky and the Brain Brain Brain Brain" -- with 4 iterations of the string "Brain".
The actual pseudo code is:
var megalomaniac = {
mastermind : "Brain",
henchman: "Pinky",
battleCry: function (noOfBrains) {
return "They are " + this.henchman + " and the" +
Array(noOfBrains + 1).join(" " + this.mastermind);
}
};
The problem in question was:
var battleCry = megalomaniac.battleCry(4);
If we indeed pass 4 as noOfBrains, since the method adds 1 to noOfBrains before joining them, would the result not have 5 "Brain"?
var multiply = function (a, b) {
//An internal comment
return a * b;
};
var stupid = "function (a, b) {
return a * b;
}"
expect(multiply.toString()).toBe(stupid);
why doesn't that work? if i remove the '' lien terminators it works but Firefox throws an unterminated string literal error.
When refreshing the browser to test the second koan, the entire section for AboutApplyingWhatWeHaveLearnt disappears. Commenting the attempted solution and refreshing the browser brings back the section with the first koan passed and the second koan in red like before.
it("should use 'any' to test if any items passes condition" , function () {
var onlyEven = [2,4,6];
var mixedBag = [2,4,5,6];
var isEven = function(x) { return x % 2 === 0 };
expect(_(onlyEven).any(isEven)).toBe(true);
expect(_(mixedBag).any(isEven)).toBe(true);
});
in lines 60-68 of AboutHigherOrderFunctions.js should be updated to use "some" instead of "any"
it looks like "any" has been deprecated?
Thanks for making these, good fun!
I'm going to fix a few typos and do a pull request..
also, I wonder if this drives the point home further?
it("should assert equality with ===", function () {
var expectedValue = "2";
var actualValue = (1 + 1).toString();
// toBe() will always use === to compare
expect(actualValue).toBe(expectedValue);
});
In the very last challenge in AboutApplyingWhatWeHaveLearnt.js, it("should count the ingredient occurrence (imperative)"
, I tried replacing the FILL_ME_IN placeholder with _(products).flatten()
to see what the effect would be. The output to the browser in KoansRunner.html is as follows:
[ { name : 'Sonoma', ingredients : [ 'artichoke', 'sundried tomatoes', 'mushrooms' ], containsNuts : false, beget : Function }, { name : 'Pizza Primavera', ingredients : [ 'roma', 'sundried tomatoes', 'goats cheese', 'rosemary' ], containsNuts : false, beget : Function }, { name : 'South Of The Border', ingredients : [ 'black beans', 'jalapenos', 'mushrooms' ], containsNuts : false, beget : Function }, { name : 'Blue Moon', ingredients : [ 'blue cheese', 'garlic', 'walnuts' ], containsNuts : true, beget : Function }, { name : 'Taste Of Athens', ingredients : [ 'spinach', 'kalamata olives', 'sesame seeds' ], containsNuts : true, beget : Function } ]
It appears to me that the flatten
function isn't actually doing anything to the products
array. Am I misusing the function or is there a problem?
In the github.io / readme page, There is a reference to URL http://pivotal.github.io/jasmine/
in "The test runner used is Jasmine with a customized report viewer."
Should that link be http://jasmine.github.io/?
This is a great project.
Just thinking, many of these koans can be solved by simply reading the english words, rather than actually understanding what's going on.
eg, you're touching on a powerful concept here
it("should use lexical scoping to synthesise functions", function () {
function makeIncreaseByFunction(increaseByAmount)
{
var increaseByFunction = function increaseBy(numberToIncrease)
{
return numberToIncrease + increaseByAmount;
};
return increaseByFunction;
}
var increaseBy3 = makeIncreaseByFunction(3);
var increaseBy5 = makeIncreaseByFunction(5);
expect(increaseBy3(10) + increaseBy5(10)).toBe(FILL_ME_IN);
});
and yet it's trivially solved without even looking at what's actually going on; you only need to read the last line (!). Although highly desirable in a real world app, this doesn't help in learning how javascript works.
Can I suggest that if this project is truly about learning the ways of the javascripts, then all function and variable names should be obfuscated such that the only way to solve the problems is to understand the javascript logic, rather than just using your intuition/everyday logic.
edit: fixing up terminology
The toString() method does not return linebreaks nor the tab'ed whitespace ('function (a, b) { return a * b; }') yet the code expects to receive: 'function (a, b) {\n return a * b;\n}'
The third assert in /koans/AboutFunctions.js asserts message to be "Outer". Either the test is named incorrectly, some other syntax is wrong, or I have a buggy version of V8.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.