Created
October 5, 2016 14:31
-
-
Save islandjoe/48c8c3758207cbe700ef7adfd718c838 to your computer and use it in GitHub Desktop.
Fizz Buzz in Swift using closure, 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
let isDivisibleBy = { number % $0 == 0 } | |
switch (isDivisibleBy(3), 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