Created
October 31, 2016 14:10
-
-
Save SlaunchaMan/194e625bb4347ac6fed879dd6b9f31b8 to your computer and use it in GitHub Desktop.
A quick FizzBuzz I wrote to show pattern matching in Swift’s switch statement.
This file contains hidden or 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 result = (1 ... 100).map { i -> String in | |
switch (i % 3 == 0, i % 5 == 0) { | |
case (true, true): | |
return "FizzBuzz" | |
case (true, false): | |
return "Fizz" | |
case (false, true): | |
return "Buzz" | |
default: | |
return "\(i)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment