Ad
  • Custom User Avatar

    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 to List<num>. Dart allows List<int> when List<num> is expected because all generic parameters are covariant in Dart and so List<int> is a subtype of List<num>. On the other hand, List<E>.reduce(E combine(E, E)) has a contravariant argument (the return value of combine). That's why it was impossible to use reduce before (all generic arguments of fold are covariant so there were no issues with it).

  • Custom User Avatar

    *Post edited for not being helpful*

  • Custom User Avatar

    I had similar problems when updating versions of some Dart kata. All I can say is that the num being a supertype of int and float, 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 :)

  • Custom User Avatar

    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.

  • Custom User Avatar

    I believe it doesn't work for empty arrays. There is a solution that shows both methods.

  • Custom User Avatar

    We don't know. We don't now what you're logging. Closing.

  • Custom User Avatar
  • Custom User Avatar

    Thank you for your kindly attention, i've fixed the case. Added the test case for sample and hidden ones.

  • Custom User Avatar

    Read the posts below asking the same.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution