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 12-hours format for 12:XX has multiple versions worldwide. It can be
12:XX PM
or12:XX AM
. In this kata, it should be specified which one should be used.In one of the example of 12-hours format, there is a
12:59 AM
. So let's assume this kata uses12:XX AM
format.However, on one of the 12 -> 24 -> 12 tests, it gave me
12:00:24PM
as the input, but expected me to return12:00:24am
as the output (when reverting back to 12).What's the logic here?
It against one of the rules: Format Preservation.
Throwing a string is not a good practice at all. The normal way is to throw a
new Error()
.And sure you can just check if any error is thrown? There's no need to forcefully make one only throws a specific error unless that's clarity requirements (which you have none of them, your error requirements are nothing but
error
and they're even strings).It's a good kata, and I enjoyed tackling it. There are just a couple of things you could change to make things a littler easier to understand and debug:
As it is, the formatting and spacing is kind of an afterthought, but in actuality, this is the main part of the kata. There are other problems making it hard to parse the instructions first time, also. With just a bit of rejigging and moving stuff around, the understandability would really be helped, I think.
The
.normalize()
method, while nice, does tend to give the coder cryptic errors from time to time. If a returned value is not a string, a test should fail or error should be thrown explicitly stating that problem, rather than an unrelated error arising after the fact, leaving the coder to scratch their heads, print out the inner-workings of.normalize()
, re-read the instructions, and so-on until they figure out what's going on.Messages like "'undefined' is not a valid time" is a bit too sparse--and misleading--to be that helpful. First, you could actually say that a value was returned, and that an error was expected.
Test.expectError
is perfect for this. Second, the input value is always wrapped in'
characters, when in reality, the value is rarely a string at all. You can useTest.inspect(value)
to generate a readable string of the value in question to use in your errors or test failure messages.But again, good job on the kata so far!
On the 24 > 12 > 24 tests, 24:XX is not a valid 24h format