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
Rounding should be used exclusively for presentation of data. By rounding you're making the result both less informative and mathematically incorrect.
Hmm I added that because whenever I use online odds converters to find implied probability, I don't want 81.2746453% etc, I just want a simple percentage with maximum one decimal place... so it was done in consideration of the spirit in which I wanted to author this kata, rather than to add another level of difficulty.
Does the practical application not really matter much for CodeWars?
IMO the whole rounding thing is a bad idea - we already have numerous katas which ask you to do that. And it doesn't make the kata "richer" (i.e. it's still the same
map
+Math.max
), but only tedious.Thanks, I'll work on this. For my random tests, I will make sure any randomly generated fractions look like real betting odds you would get, so I'll set a maximum of 1000 (still probably higher than you would normally see), and make sure the other number is 9 or under, so 1/1000 or 1000/1.
Then I'll take another look at the rounding and get cracking on those tests. Thanks for all the suggestions!
Something with a result like
*.25
to filter outMath.round
, which rounds to even.And something with a result like
*.*5
that is an infinite fraction in binary, for example:Test.assertDeepEquals(oddsConverter(['999/1001']), "50.1%");
Yeah, random tests can be hard. :]
I've though writing random tests for a 7 kyu kata can feel like solving a 2 kyu kata. Writing them for more difficult kata can actually be easier sometimes.
Derp, sorry, should be rounded up.
What kind of tests does it need for rounding?
I'm currently creating random tests, but this is a kata in and of itself!
That's surprising... Then even your solution is incorrect. In any case there should be tests with all kinds of rounding.
5 rounding down in all cases.
Random tests needed.
Rounding direction of values like
*.*5
is unspecified.