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.
Description:
But there are no empty arrays in the tests. That's too bad. Because in this case solutions with reduce would not work.
Yes, it work now.
@monadius, thank you very much!
I updated Dart random tests. Now
reduce
should work.Dart random tests called the solution function with an argument of type
List<int>
. I changed this type toList<num>
. Dart allowsList<int>
whenList<num>
is expected because all generic parameters are covariant in Dart and soList<int>
is a subtype ofList<num>
. On the other hand,List<E>.reduce(E combine(E, E))
has a contravariant argument (the return value ofcombine
). That's why it was impossible to usereduce
before (all generic arguments offold
are covariant so there were no issues with it).*Post edited for not being helpful*
This comment is hidden because it contains spoiler information about the solution
I had similar problems when updating versions of some Dart kata. All I can say is that the
num
being a supertype ofint
andfloat
, connected with the way how type inference works in Dart, makes things utterly confusing.I didnt fully grasp how it works, I remmebr that I just sprinkled type annotations and casts to
num
until I got it working :)If you check the stack trace, then you can see the error is coming from reduce function itself. So, yes, problem with the code. I don't do Dart, so I don't know why, but adding
[...arr]
works somehow.This comment is hidden because it contains spoiler information about the solution
I believe it doesn't work for empty arrays. There is a solution that shows both methods.
This comment is hidden because it contains spoiler information about the solution
We don't know. We don't now what you're logging. Closing.
Pretty nice, thanks for yours solution
Thank you for your kindly attention, i've fixed the case. Added the test case for sample and hidden ones.
Need a test like
['xyz', 'abc', 'xyz']
My solution passed all the current tests, but it wouldn't have passed this one.
Loading more items...