DEV Community

Discussion on: Daily Challenge #97 - Greed is Good

Collapse
 
juliannicholls profile image
Julian Nicholls

Hi, Julian here!

There are two subtleties that catch out a great deal of the people who try this on Codewars.

The first is mentioned in this article, don't mutate the input.

The second is shown up by this combination: 3 3 3 3 2
That should score 300, but many people end up incorrectly giving 0 as the score.

Collapse
 
qm3ster profile image
Mihail Malo

Why do they give 0?!

Collapse
 
juliannicholls profile image
Julian Nicholls

The problem comes when there aren't exactly three of a number.

Thread Thread
 
qm3ster profile image
Mihail Malo

I guess that's no more contrived than the solution that would give 600 so that's okay.

Collapse
 
dwilmer profile image
Daan Wilmer

What do you mean with "Don't mutate the input"? The variable that is given isn't changed, right?

Collapse
 
juliannicholls profile image
Julian Nicholls

In some languages on Codewars (Python is the problem here, I think) it is possible to mutate the array that is passed as input. That will guarantee that the test will fail.

Generally it is not good to mutate the input to a function, unless that is the expected behaviour.