Created
June 16, 2014 17:31
-
-
Save alexwirz/aee3ab15f6a6d6289a70 to your computer and use it in GitHub Desktop.
Fizz Buzz in Swift
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
import Cocoa | |
func fizzBuzz (number : Int) -> String { | |
let (n,m) = (number % 3, number % 5) | |
switch (n,m) { | |
case (n,m) where n == 0 && m == 0: | |
return "FizzBuzz" | |
case (n,m) where n == 0: | |
return "Fizz" | |
case (n,m) where m == 0: | |
return "Buzz" | |
default: | |
return number.description | |
} | |
} | |
let numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] | |
numbers.map(fizzBuzz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment