Ad
  • Custom User Avatar

    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:

      if (name === 'Johnny') return 'Hello, my love!';
    

    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. :-)

  • Default User Avatar

    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.

  • Default User Avatar

    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

  • Default User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    Brackets are optional for single line if statements (but some people prefer to add them for clarity).

  • Custom User Avatar

    How does this function work without the opening and closing {}'s after the conditional if statement?

  • Custom User Avatar

    With arrays you are better off using Test.assertSimilar().

  • Default User Avatar

    Have you tried Test.assertEquals(getEvenNumbers([1,2,4]), [2,4], "a message");?

  • Custom User Avatar

    From what bkaes is saying and by looking to your code the following wouldn't work:

    var HowMany = [1,6,0,5,0,0];
    var Type = ['house', 'car','jeans','pen','something','other'];
    

    Because it returns:

    ["jeans", "jeans", "jeans", "house", "pen", "car"] [0, 0, 0, 1, 5, 6]
    

    instead of

    ["jeans", "something", "other", "house", "pen", "car"] [0, 0, 0, 1, 5, 6]
    
  • Default User Avatar

    Hey=) Nice Kata, waiting for the 2nd part!

  • Custom User Avatar

    Thanks, I am glad you appreciated it! :)

  • Default User Avatar

    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=)

  • Default User Avatar

    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=)

  • Default User Avatar

    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...