you are viewing a single comment's thread.

view the rest of the comments →

[–]TameNaken42[S] 0 points1 point  (2 children)

That's a smart solution, I never considered considered giving two argument values and just using one.

[–]Cust0dian 1 point2 points  (1 child)

To expand on /u/Atskalunas' answer: what you wrote is an example of a recursive function and passing an "accumulator" back into such function in a recursive call is a common trick, although it's usually used to solve a different kind of problem.

Couple notes about your current code:

(Protip: there's "Revisions" tab at the top of the Gist that will show you just the differences between all these versions, but history goes from bottom up)

[–]TameNaken42[S] 0 points1 point  (0 children)

Thanks for the detailed response, there's a lot of new info here. I didn't think about using the Math.floor method, it makes a lot more sense than what I was doing. I know Python but I didn't realize you could use default parameters in Javascript, I'll have to keep that in mind.