Skip to content

Instantly share code, notes, and snippets.

@junebash
Created November 6, 2019 16:22
Show Gist options
  • Save junebash/9a1aa86d61f53fdb04ef159d6311ab75 to your computer and use it in GitHub Desktop.
Save junebash/9a1aa86d61f53fdb04ef159d6311ab75 to your computer and use it in GitHub Desktop.
Coding Challenge U2S2 (2019-11-06)
func fizzBuzz(_ n: Int) -> [String] {
if n < 1 {
return []
}
var output = [String]()
for i in 1...n {
var stringForI: String = ""
if i % 3 == 0 {
stringForI += "Fizz"
}
if i % 5 == 0 {
stringForI += "Buzz"
} else if i % 3 != 0 {
stringForI = String(i)
}
output.append(stringForI)
}
return output
}
print(fizzBuzz(15))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment