iOS Closures in Swift First Class Functions Extending the Int Type

Zenek Barburka
Zenek Barburka
7,009 Points

Closest multiple of 6 for 32 is 36?

I understand that it's just an example ilustrating the concept, but as it is content for which I pay I would like it to be without basic errors like this one.

1 Answer

Ryan S
Ryan S
27,253 Points

Hi Zenek,

It is not so much an error regarding the concept of multiples, but more to do with the fact that the function is written in a such a way that it will always return the closest multiple of 6 that is greater than the value you give it. In other words, it does exactly what it is supposed to, regardless of its name.

The logic basically is "if the current multiple in the range of multiples is greater than the value AND the difference between them is less than 6, then return the multiple". The function doesn't consider the case for which it is less than the value.