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.
ways
array contains different solutions for this Kata.stringToNumber
function executes all the functions in the array and then compares their results using thecheckThemAll
function.checkThemAll
function checks each next element. If at least one is incorrect, it will return NaN (and the tests will fail).Thus, we just execute all the functions in the
ways
array sequentially and check that they all give identical results.Frankly, these were my first steps in JavaScript. So I just got carried away experimenting with type conversions.
And I'm not an alien, I'm a human :D
This solution doesn't work. It only checks two things:
But test cases do not contain such an elementary check. As always :)
I thought I was smart. But some people have found a way to solve this Kata in one line :D
Having solved this problem, I wanted to write that there is an inaccuracy in the description. But then I realized that this Kata imitates the real world. In the real world, you are distracted by stories about juniors, seniors, bosses, stackoverflow, etc. And no one says where the bug really is.
JavaScript test cases do not provide arrays like
[1000, 0, 1, 0, 0, 0, 0]
or[10, 0, 0, 0]
.Many existing solutions will break on such tests.
As I can see, the same issue was already closed for Python 4 years ago.
But for JS, the problem is still relevant.
But this is not how reduce works! Why are you all creating an initial value? If it is not given, then the first element of the array becomes the initial value.
Because the goal of your program is to determine that one of the players won.
Otherwise, they will continue to play.
Because in real life, your program must determine by itself at what point one of the players won.
Otherwise, players will continue to make moves.
P.S. Sorry for my bad english. I hope I have explained it clearly.
It looks like there is a bug in the test cases.
For input
'abcdefghijklmnopqrstuvw xyz'
the expected result is
'abcdefghijklmnopqrstuvw -\nxyz'
But it seems to me that the following result is more correct:
'abcdefghijklmnopqrstuvw \nxyz'
(with one or two spaces, but not with a hyphen)It was a useful Kata. Now I know that
localeCompare()
does not work correctly with punctuation marks.Live and learn...
Please make the error messages more informative (JavaScipt).
P.S. Okay, I found my mistake. And I liked this Kata :)
Nevertheless, errors should be described in more detail.
Yes, it was a painful Kata that left mixed impressions. Not so bad actually =)
If you need a hint, maybe this will help.
count == null
, it should be manually coerced to 32 (the default function parameter does not work fornull
).And this as well:
PS: Please don't mark this comment as a spoiler. It's just a hint for solving a poorly composed Kata.
JavaScript
Hi! I see many people consider this Kata to be simple. =)
If you really succeed in solving it, pleace explain to me this.
Random tests:
Let's take only numbers:
It doesn't look like a sorted array. And I can't figure out how to find any pattern.
Either the test cases are broken, or the problem needs to be better explained.
Loading more items...