What I learned from writing six functions that all did the same thing

Jackson Bates

1.2K37

That specification seems ambiguous:

“The challenge seemed simple enough: return the sum of all multiples of 3 or 5 that are below a number N, where N is an input parameter to the function.”

I assume that I, the programmer, have a choice of writing the code to sum multiples of 3 or to sum multiples of 5. I suppose there could have been a parameter of some sort indicating whether to sum multiples of 3 or multiples of 5, but the specification already mentions N as a parameter, presumably the only parameter. It is awfully hard to write an unambiguous specification.

The closed form solution sort of jumps out. I was surprised anyone tried to do this with a loop.