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!
One issue I could see with this is the "magic numbers". I think for best readability later it would be good to give everything an explicit variable name.
me rn xd
Nice solution
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.
Thank you, didn't know that.
reversed
doesn't modify the list, it creates an iterator on the list in reversed order. It's the same as you are doing, but no need to bother with indexes.I see that it reverses numbers list and then loops from first element to last. It's not the same as what I said: keeping list unchanged and just starting with last element by using indexes. See following snippet :
for i in range(len(numbers)-1, -1, -1):
That's what the solution does.
No need to reverse numbers if you can just iterate backwards.
Loading more items...