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.
The test cases included assert that the get_all(...) value is equal to undefined instead of the number provided because of a misplaced parenthesis.
The given test cases don't run since they use assertEqual instead of assertEquals.
Also, I was able to submit a solution that would break if cats had the same name.
There are a few minor issues from my perspective:
It's confusing why in the case when there are two numbers next to each other, 17 and 18, why they'd be outputted seperately instead of combined into one range 17-18.
The phrase "Numbers in a string in ascending order" in the description should be "The numbers in the string will always be in ascending order.".
It feels a bit arbitrary to me why you'd have the restriction that the numbers are in ascending order, but then also allow non-number input.
Those minor issues aside, just as a suggestion, this question would be more clear to me if instead of being minimiseString, it was createRanges, which would take an unordered array of numbers, e.g. [1, 3, 2, 5, 4, 9, 8, 7], and returns a sorted array of ranges, e.g. [[1, 5], [7, 9]].
Thanks for changing it. Looks good to me.
One minor issue:
None of your test cases test to see if left is a valid move. My initial solution should have been rejected (left was defined as diagonal, but it still passed all the test cases). You may be able to test this just by switching exit and miner in your test cases.
The example test cases you provide have incorrect results. Namely, the number you initially provide is not a valid lucky number, but the test treats it as one. And the second test has the same issue.
The example test cases use matrixMultiplication as the name of the function, but the actual test cases and solution setup use matProd.
Also, there apparently are some comments on the bottom as hints, which I guess I completely missed or something (was it below the fold?) I'm not 100% people will see that, and it makes the solution look sort of bad. Maybe moving the hint to the description? Also I'm not sure it's that valid a hint, since most of the solutions so far are all in one method.
Wow! Thanks for making those changes. One other small thing is that the example test cases need to get updated so that they check for an array instead of a single piece.
Regarding the timeout, I think it's probably more an issue with my initial solution being really inefficient... I'll add a feature request if there isn't one already for codewars print the test/log output even when there's a timeout.
Thanks! I guess I'm also having trouble understanding why there could be test cases where activeUse could be larger than needFor. The way I read the kata, needFor is the total usage for the phone, and activeUse is the total active use for the phone. Implicitly the idle time is the maximum of 0 and needFor - activeUse. But when I look at your solution, you subtract them directly (so idle time could potentially be negative?). I guess I'm just a little confused as to what these parameters really mean.
I'm not sure what this test case is supposed to mean.
Test.expect(results5.hasJuice(20, 20, {extra:0, minutes:0}).true == 0, 'Expected false, instead returned ' + results5.hasJuice(120, 30, {extra:0, minutes:0}) )
Yeah, I agree it would be more clear if you explained what you wanted instead of doing it indirectly with test cases. You can also see there are some solutions that are not really the intended lesson (e.g. the one that was doing a foreach over an array of numbers). To fix this, you could add a randomized solution, but that may obfuscate what the real requirements of the kata are even more if you rely only on that.
You could potentially generalize this too, so that the input function took a function that took one argument and a min and max range, and outputted an array of functions which could be called with no arguments whose value at index i would be the ith value in the range. Sort of like a getPromisesInRange(fn, xMin, xMax) function.
I agree. I had to reveal the solution to understand what you really wanted to return because your examples were unclear. It's also really hard to relate it to anything. Even though I sort of get what you're asking, I really don't want to put the effort to code a solution to this because currently it feels nonsensical.
Interesting problem... it took me a while to get a solution that passed the test cases without timing out. That may be a limiting issue for this kana because people with working solutions will still fail the test cases (with an unhelpful timeout error message).
I would also mention technically you can do en-passant with your pawn if you know the other player moved that pawn the previous turn (information we don't have currently have, so I'm ignoring). You may want to add a line mentioning that to the description.
I think it may also be possible to have multiple threats. For example, if a rook was blocking a bishop from attack the king, and then the rook was moved so that both the bishop and the rook were attacking the king, then technically the king would be threatened by multiple pieces.
Ah, that's true! I've added that test case. I'm not 100% sure how you'd even them out to be guaranteed the optimal solution, but I look forward to a cool solution.
I like your solution! It's way more efficient than the brute force one, especially when there's a lot of columns. I'm not sure if there's a test case that breaks it.
I agree it's more straight forward to include the initial 0. I've modified the kata so that the output is an array of starting indexes including the initial 0.
Loading more items...