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.
The sum method will return an Int which can cause problems for large values.
Here foldLeft is used to convert the values to long format as they are sumed.
thanks for the advices! Im a begginer on this language and its always good to learn new ways to do the same
In case of reduce, initial value is the first element of the list. For puprose of this kata we can assume list is not empty so initial value is not needed. Take a look at kata details.
I've tried other options too:
https://www.codewars.com/kata/reviews/5a6bb48a07365e9dad000005/groups/5ac759fa52763ee0030025a4
https://www.codewars.com/kata/reviews/5a6bb48a07365e9dad000005/groups/5a6c62d7512a62e44300060b
This one is the fastest one-liner. The first one is probably slower because it's filtering
Long
s instead ofInt
s, the second one - because of an extramap
, although I'm not entirely sure about the reasons.But this is still significantly faster:
https://www.codewars.com/kata/reviews/5a6bb48a07365e9dad000005/groups/5a6c66fb3a8fbdad4c000157