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.
You have a point and I agree with you about the one-liner problem (even if it's going against what I wrote three years ago).
Nowadays I don't use bracket with one-liners that can be written on the same line of the
if
, often for early exits:Otherwise, I like to use brackets mostly to make all if-statements look the same. Consistency makes things easier to read in my opinion. (And clear rules are easier for a team to follow and for tools to enforce.)
Refactoring out a function whenever there are a few lines, Uncle Bob-style, is another discussion. :-)
I would not say, that it is best practice, it is coding conventions. And in the majority of coding conventions the brackets are demanded.
I had to work without brackets and I must say since then the code without brackets is much easier to read.
The main argument is allways, that you may add a line outside the conditional block. In my expierence this never happens. And if it happens your test should fail. And if you have to add lines to a conditional block, it maybe time to refactor a methode which a catchy name.
I was also confused by the description, ignored it, looked at the test cases and then solved the kata.
Suggestion:
Length of output: n
Fill output with [1x, 2x, 3x, (...), nx]
If you think that would be too short: http://www.joelonsoftware.com/uibook/chapters/fog0000000062.html
Not sure what programming language you're using, but, "[optional] message" should be a string. Try it in quotes, like I have it here, for example, or replace it with a string variable. I see zvytas suggested basically the same thing. As for whether or not it will test arrays, I don't know. You may have to write your own array comparing function and pass the results of that to a test. Probably not... but I'm just learning the test stuff too, so I'm not sure yet. Also, it's different for different languages.
I would even go so far as to say that using the brackets are best practice. It's easy to start out with a one-liner and forget to put in the brackets when you add another line to the conditionaly block.
Brackets are optional for single line if statements (but some people prefer to add them for clarity).
How does this function work without the opening and closing {}'s after the conditional if statement?
With arrays you are better off using
Test.assertSimilar()
.Have you tried Test.assertEquals(getEvenNumbers([1,2,4]), [2,4], "a message");?
From what bkaes is saying and by looking to your code the following wouldn't work:
Because it returns:
instead of
Hey=) Nice Kata, waiting for the 2nd part!
Thanks, I am glad you appreciated it! :)
A little bit more difficult than it seemed at first.
It was interesting to solve it.
Most time gone to check all exeptions.
But good instruction were written, so I think this Kata is ready=)
Thank you 4 this Kata!!
I feel like it is magic)))
I spent a half of the day to solve it, but it's unbelievable feeling=)
The same, kata is easy, but it took a huge amount of time to understand what is going on here...
One example could have explained more than thousands of words...
Loading more items...