YOUR TESTS TIMED OUT (Swift)

Help!
Your tests timed out. This might mean that there was an issue in our infrastructure, but more likely it suggests that your code is running slowly. Is there an infinite loop or something similar?

Please check your code, and if nothing seems to be wrong, try running the tests again.

func dailyRateFrom(hourlyRate: Int) -> Double {
  return Double(hourlyRate * 8)
}

func monthlyRateFrom(hourlyRate: Int, withDiscount discount: Double) -> Double {
    let x = Double((hourlyRate * 176) - (((hourlyRate * 176) * discount) / 100))
    return x.rounded()   
}

func workdaysIn(budget: Double, hourlyRate: Int, withDiscount discount: Double) -> Double {
    
    let y = Double(budget - ((hourlyRate * 8) - (((hourlyRate * 8) * discount) / 100)))
    return y.rounded(.down)
}

This code looks like it ought to run fairly quickly. Sometimes the test runners are overloaded. Did you try adding a newline and rerunning?

I ran your code in Xcode playgrounds and it appears it doesn’t like the nested calculations going on for setting the x & y properties. Try breaking some of the logic out into separate lines (see example code) which will have the added benefit of being more it more human-readable and help others understand your code better…

Example Code:

func workdaysIn(budget: Double, hourlyRate: Int, withDiscount discount: Double) → Double {
let dailyRate = TODO calculate daliy rate
let discountedDailyRate = TODO calculate daliy rate
let workdays = (budget / discountedDailyRate).rounded(.down)
return workdays
}

From the Swift Style Guidelines…nothing wrong with a few extra lines of code if it improves intention/readability!

“Clarity is more important than brevity. Although Swift code can be compact, it is a non-goal to enable the smallest possible code with the fewest characters. Brevity in Swift code, where it occurs, is a side-effect of the strong type system and features that naturally reduce boilerplate”