Or if you want to skip ahead to more advanced Swift usage (without the early return optimization), consider this:
func isPassingGrade(for scores: [Int]) -> Bool {
scores.reduce(0, +) >= 500
}
There’s no explicit sum() function in the Swift library but this reduce() expression is equivalent. And reduce() is well worth getting familiar with.
Topic:
Programming Languages
SubTopic:
Swift
Tags: