Ad
  • Default User Avatar

    My solution works but Codewars Environment throws and error.
    "solution.swift:23:31: error: value of type 'Duration' has no member 'formatted'".

    Duration does have the 'formatted()' method.

  • Custom User Avatar

    That's just another way of writing the same thing. It comes down to personal preference. Although, I would argue that since guard is specifically meant for returning early from a closure, which is what we're doing here, it makes more sense in this context than if.

  • Custom User Avatar

    Why would you use guard here? Can't we just write if (num < 3) { return 0 }?

  • Custom User Avatar

    Exactly what i was thinking. I first tried it like above, but it was throwing me an error. But i think mainly because i used "for i in 1..<num" and it was checking with 0.

    I nested the whole thing in a "if num > 0 {...} else {return 0}" but mainly cause i'm not much familiar with guard. :D Thanks, gonna look into that again.

  • Custom User Avatar

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

  • Default User Avatar

    I get this message when using FrankK's solution:
    error: winningNumber.playground:72:13: error: 'random()' is unavailable in Swift: Use arc4random instead.
    return (random() % limit)+min

    But, arc4Random_uniform, also does not work, although it works perfectly in Playgrounds.