Created
November 6, 2019 16:22
-
-
Save junebash/0c8af6b55efe713451a4ca79a72f539c to your computer and use it in GitHub Desktop.
Coding Challenge U2S2 (2019-11-06)
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
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