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.
Your code is wrong.
Really.
Haha hallelujah!
I was referring to kreitzo code, not yours, which seems fine this time ;)
Always nice to hear from you mate :D
Your code is still, if you allow me, quite ugly, not easily maintanable (using an associative array or a
switch
instead of a pointless list ofif
s?) and fails to consider cases liket===80
.From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce:
The initial value is like a backup value for when it's empty/only one item or there's a NaN value at index 0. Since reduce works by looking at index 0, if there's nothing there it returns an error.
array !== []
is true. This means it will try to sort the null value; leading to an error.you cannot do that.
That's a good idea, however, look at this case:
{ '0': 'aBC deF Ghi', '1': undefined }
. The second argument is "undefined" which means that the length of arguments is != 1 and therefore split() is performed on the undefined value. You should get into default arguments/parameters because they are really simple to make.Sorry, this is a bug with the tests. They use
titleCase(foo, undefined)
instead oftitleCase(foo)
and soagruments.length
is always2
. See(which might need more emphasis?)
Unfortunately I can't change the tests now as too many people have passed the kata.
The error is when there is not a second argument in the function. Your code tries to split
minorWords
, however this may not be included as an argument and therefore you need a default argument. You should also put the empty string/null/undefined check at the start so that it will return early and will not follow any other code.Here is one:
Fixed, as per above comment. Thanks.
if(array == null)
That checks for null. ;-)
What were the errors? Suggests there aren't enough random tests if sometimes you can pass when you shouldn't
Loading more items...