Fundamentals8 / 8
Up next

guard for early exit

// guard unwraps an optional or leaves the scope early
func firstEven(_ nums: [Int]) -> String {
    guard let hit = nums.first(where: { $0 % 2 == 0 }) else {
        return "none"
    }
    return "found \(hit)"
}
print(firstEven([1, 3, 6, 7]))
print(firstEven([1, 3, 5]))
What you're solving

guard let unwraps and bails out