Ad
  • Custom User Avatar

    Description:

    If the input array is empty consider it as: [0] (array with a zero).

    But there are no empty arrays in the tests. That's too bad. Because in this case solutions with reduce would not work.

  • Custom User Avatar

    Yes, it work now.
    @monadius, thank you very much!

  • 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

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

  • 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

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

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar
  • Custom User Avatar

    Pretty nice, thanks for yours solution

  • 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

    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...