Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Nice one, although it required more typing. The obvious solution required none at all.:)
Wow, this is clean
niceeeeee Kata.
Your Kata was so gnarly :) , that I wanted to create similar Kata with template literals. Check me out!
Might not be correct for inputs that add up to 45 but digits are not 1 to 9.
Same as mine :p
Nice!
Clever... Can anyone explain it to me!
Not to change the code... just to debug!
Fukin boss!
did you try solving it wihtout iterating thru the entire array twice?
I like this solution, inspired me to use interpulationa in ec6, also called template literals.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
Thank you so much! This was incredibly helpful. I really appreciate you giving me such a thorough and detailed explanation. I totally understand now.
Your code does not work as intended becasue of the so-called 'operator precedence'. This determines the order in which the operators are evaluated. For example the multiplication operator '*' has a higher precendence that the '+' operator. This means that the following operation,
1 + 2 * 3
equals 7 and not 9.
Now, in your code,
function greet(name){
return "Hello, " + name === "Johnny" ? "my love!" : name + "!";
}
'+' has higher precedence than the '===' which has a higher precedence than the conditional statement '… ? … : …'
This means that the code will be evaluated as:
function greet(name) {
if ("Hello, " + name === "Johnny") { // Concatenate first and after this check if the result equals to "Johnny".
return "my love!";
} else {
return name + "!" // 'Johnny!' is returned
}
}
In order to avoid this, we have used the parentheses to create the grouping operator '(...)' which has the highest precedence in JavaScript.
You can check the operator precedence here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
I also recommend this short article with examples: http://blog.stchur.com/2006/07/14/the-javascript-ternary-operator/
Please up-vote my answer if it helped you. Thank you :)
This comment is hidden because it contains spoiler information about the solution