Created
June 5, 2018 15:43
-
-
Save nerdsupremacist/a8ced19beddb3d0202410d737ed10b69 to your computer and use it in GitHub Desktop.
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 Foundation | |
let fb = [ | |
3 : "Fizz", | |
5 : "Buzz", | |
6 : "Fizz", | |
9: "Fizz", | |
10: "Buzz", | |
12: "Fizz", | |
15: "FizzBuzz", | |
] | |
func fizzBuzz(until n: Int) -> [String] { | |
guard n > 0 else { return [] } | |
return (0..<n).map { fb[($0 % 15) + 1] ?? String($0 + 1) } | |
} | |
fizzBuzz(until: 100).joined(separator: "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment