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.
This comment is hidden because it contains spoiler information about the solution
This is such an elegant solution
I just feel like to say that I like your solution the most
Самое крутое и простое решение с минимумом условий и вычислений!
This comment is hidden because it contains spoiler information about the solution
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
Very much so! We should avoid processing unnecessary data, especially when the problem itself points out that the input array might be very large.
This comment is hidden because it contains spoiler information about the solution
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 returntrue
.Thanks for your feedback! :-)
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!)
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.
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!
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 returnfalse
. After that you probably need to rewrite your solution to handleisMerge('banana', 'bana', 'an')
which should returntrue
.Thanks for providing your code, it makes it much easier to answer.
Thanks for taking interest in the kata and good luck! :-)
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution