Ad
  • Custom User Avatar

    No casting is needed, Object is mother and father of all types :-)

  • Custom User Avatar

    +1 this solution is clearly not optimised

  • Default User Avatar

    If someone writes code like this for such a simple thing, they will not bother to read more complex code knowing that it could have been coded simpler.

  • Custom User Avatar

    Another way to do it is to preallocate the capacity and then use append with the ... operator. Eg: results = append(results, signature[:n]...)

  • Default User Avatar

    I guess append() would create a new slice each time it cannot fit the numbers anymore, so it might be inefficient compared to creating a slice the size of n int in the first place. Although the code is really clean and short, I liked that.
    UPD: Oh! And a slice created like that will address the underlying values of that array, you should use predefined copy() function.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    I wanted to solve in the same way, but i wondered whether the code should check for the necessity to return NO in every iteration of the switch-case cycle. The reasoning is that with this code above (if I get it right) at a certain moment while the queue goes on we might not have the change, and let's say the variable twentyFives first becomes a negative, but then becomes positive again, which allows us to pass the final test in the body of the "if" statement. I will try to illustrate:
    the order of bills is 25, 25, 100, 25, 25. The value of the "twentyFives" variable will change the following way: 1, 2, -1, 0, 1. We pass the final test, but in reality we cannot give the change to the guy with a 100 bill and therefore we did not serve every client in the line.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Could somebody please explain, why don't we have to convert the string to Object type, whereas it is a necessity when we return false in this Kata? I guess it's because the Object type is a class-generated type (not an object type as such, the one that begins with lowercase), but i can't think this through any further.

  • Default User Avatar

    I like this one more than others in terms of being less obvious

  • Default User Avatar

    It would be more readable if you used the "$" sign before each string you return, it would not be so colorful this way. Otherwise it is just the same as mine, except for the initialized int at the end of the code.