Skip to content

Instantly share code, notes, and snippets.

@nerdsupremacist
Created June 5, 2018 15:43
Show Gist options
  • Save nerdsupremacist/a8ced19beddb3d0202410d737ed10b69 to your computer and use it in GitHub Desktop.
Save nerdsupremacist/a8ced19beddb3d0202410d737ed10b69 to your computer and use it in GitHub Desktop.
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