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.
avoid declaring global variables
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
If I understand correctly, this works because it assumes the array.length is < 1000. Would cause a nasty bug in production ;)
Cheeky bastard... I love it!
Please consider this is used in a real codebase:
The above outputs
[]
instead of[2,3,5]
, because the arrayfoo
was modified from inside thedistributionOf
function. Functions shouldn't mutate their parameters.Please consider this is used in a real codebase:
The above outputs
[]
instead of[2,3,5]
, because the arrayfoo
was modified from inside thedistributionOf
function. Functions shouldn't mutate their parameters.Please consider this is used in a real codebase:
The above outputs
[]
instead of[2,3,5]
, because the arrayfoo
was modified from inside thedistributionOf
function. Functions shouldn't mutate their parameters.Please consider this is used in a real codebase:
The above outputs
[]
instead of[2,3,5]
, because the arrayfoo
was modified from inside thedistributionOf
function. Functions shouldn't mutate their parameters.Thanks for the feedback! I'm surprised that a test case did not cover that.
A good practice is to always specify second parameter for parseInt(): radix, in this case it should be 10. Otherwise if the array contained 0 you could be in for a surprise ;)
A good practice is to always specify second parameter for
parseInt()
: radix, in this case it should be10
. Otherwise if the array contained0
you could be in for a surprise ;)I think you can either drop the filter part or change regexp to
/(, )(\S+)$/
(or even/, (\S+)$/, 'and $1'
) to avoid redundancy.I like how this solution doesn't count $100 bills, that some (indluding me) unnecessarily keep count of…