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.
JavaScript version of this could really use a "don't use eval() or similar" clause.
this.number = number
? Is there some gain achieved by that?Why create the additional variable
i
? There's nothing wrong with modifying thenumber
parameter (which is a copy, and won't affect anything on the caller's side).There's no reason to start i at 0; you can start it at 2. You can also put each if condition into one expression and take advantage of short-circuit evaluation. (I'm assuming the reason you used an else if is to avoid doing the extra check of an || expression because as soon as you know i % 3 === 0, there's no need to check the other case -- but that's how boolean expressions work anyway :))
You need to declare
sum
andi
withvar
; as is, this spills them out as globals.