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.
@juanignaciomalerb4 Incorrect. If the array is empty, then 0 / 0 is done, which results in
NaN
(which is the expected result).ooooh it makes sense now
I think because in the sum prototype he gives an initial value of 0 in the reduce function. So if an empty array is passed that will be the default value
This comment is hidden because it contains spoiler information about the solution
I think they're equal. It's just the arrow one is shorter
what about empty array? does average() method still work?
some faith returned after this kata thx buddy <3
This comment is hidden because it contains spoiler information about the solution
Is there any particular reason to use strict (in)equality here?
Where is division by 0 Test ?)
Not the always, but only a one time during the initial initialization (self-invoking function). This migh explain something re initial initialization https://en.wikipedia.org/wiki/Memoization
When you pass a function from the outside as a parameter a code evaluation interpretator won't need to reinitialize the function every time when sun/whatever dependent function execution happens.
So when you for example do reduce in this way
then reducing function initialization happens every time when you call the
someFunc
, in my opinion it's not the most optimal way, but I believe nowadays JS interpretators are able to omtimize such cases automatically.I'm asking because I don't know (not to say you're wrong). Is using closure here really a better way? What benefit does this give? It seems like you'll still have an anonymous functon anyways (return function() {}).
I think it might be better using
===
or!==
.Nice touch reusing sum in average.
I was expecting to find an answer like this after I submitted my 50 line solution. Excellent, thanks a lot!
Loading more items...