Last active
October 5, 2016 13:30
-
-
Save islandjoe/0b505fce8c8534becadd2e1930eaa471 to your computer and use it in GitHub Desktop.
Fizz Buzz in Swift 3 using extensions, switch, and tuples.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Int { | |
func isDivisible(by number: Int) -> Bool { | |
return (self % number == 0) | |
} | |
} | |
func fizzBuzz(_ number: Int) -> String { | |
switch (number.isDivisibleBy(3), number.isDivisibleBy(5)) { | |
case (true, false): return "Fizz" | |
case (false, true): return "Buzz" | |
case (true, true): return "Fizz Buzz" | |
case (false, false): return String(number) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment