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.
This solution uses two loops (filter and sum) instead of one for loop in the traditional one. So yes, in the terms of performance this is definitely not the best solution.
Question! does it return 0 when the array is empty or has just a 0? I guess so. It wouldn't be approve otherwise but I was not sure about it and my approach was pretty similar instead I used v -> v >= 0, maybe unnecesary after a double check 🤔
it's very conventient once you wrap your head around it and will trivialize a lot of problems
ong, i didn't know that thing existed
I did not know that Java has functional patterns / iterators. Nice!
me rn xd
Using loops hurts my brain less, I'm still trying to wrap my head around streams
you used stream because it looks cool, i used stream because i'm too lazy to type a loop solution.
we are not the same.
It's not a bug, it just performance test...
You went over primitive range.
Clever solution, but for this particular Kata I prefer the traditional for loop.
I'll never use Streams for small data, or simple loops like this one. This is easily a one liner with a for loop and the gain in readability is probably none.
Please use spoiler flag next time.
This comment is hidden because it contains spoiler information about the solution
First, what I can see, is memory usage, because a Stream is an Object by himself and it consumes more memory for links, metadata, etc than a single int variable in the solution below. Then filter statement use lambda which is Anonymous class instead of plain if statement. Not sure about performance, because I don't know a lot about how stream executes, but it can be easily tested. In another hand, stream can be executed parallel (check Arrays.parallelStream() or Stream.parallelStream()) what is easier to use than write parallel code by yourself.
In conclusion, I will say that for this kind of tasks it's better to use default loops and ifs, because task is pretty simple and solution will look clean and easy to read. But when you have a lot of intermediate operations with objects streams will look much sweeter.
very clever young sire
Loading more items...