Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This is such an elegant solution

  • Custom User Avatar

    I just feel like to say that I like your solution the most

  • Custom User Avatar

    Самое крутое и простое решение с минимумом условий и вычислений!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    In fact I was caought up here too thinking the same thing, the answer is simple : it's about " Operator precedence "
    you've been thinking of that expression like this :

    return ( i+k > a.length ) || ( s.length >= a.slice(i,i+k).join('').length ? s : a.slice(i,i+k).join('') );

    In fact it is interpreted like this

    return ( i+k > a.length || s.length >= a.slice(i,i+k).join('').length ) ? s : a.slice(i,i+k).join('');

    Because the || operator take precedence over the ? operator

  • Custom User Avatar

    Very much so! We should avoid processing unnecessary data, especially when the problem itself points out that the input array might be very large.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Your example should absolutely return false, but I doubt that the random test cases are wrong. They have been checked a lot of times already.

    There is a problem with your code, though. And there isn't a specific test case to catch that particular bug. (Wish I could add test cases after the kata was published.) With a bit of (bad?) luck, the random tests won't expose it either.

    Try running your code on isMerge('ananas', 'anas', 'na'). It should return true.

    Thanks for your feedback! :-)

  • Custom User Avatar

    Your "random string" test cases often expect true when they should be false. If the same character exists at a given char position in part1 and part2, it expects true, but should be false. I passed by re-submitting a few times until this stopped happening, receiving different numbers of failed tests each time

    e.g. s="test;ab", part1="te;a", part2="st;b" - expects true but should be false (at least that's my interperetation of the problem!)

  • Custom User Avatar

    Yeah, those kind of things were not clearly stated in kata's description or tests(from RUN TESTS button).
    Otherwise, the kata itself is very fun and I will still try to solve it.

  • Custom User Avatar

    Oh, and if you are still not convinced, please tell me which test case you think is wrong and I'll take a look at it.

    Thanks again!

  • Custom User Avatar

    You should probably check the test case you failed a bit closer, I can (almost) promise you that they are correct. (1500+ successful solutions.) Note that the description explicitely states that some things you need to figure out from the test cases.

    To give you a nudge in the right direction, you could start with a minor adjust for isMerge('ab', 'ab', 'b') which should return false. After that you probably need to rewrite your solution to handle isMerge('banana', 'bana', 'an') which should return true.

    Thanks for providing your code, it makes it much easier to answer.

    Thanks for taking interest in the kata and good luck! :-)

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution