We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2c47dc3 commit 99d769dCopy full SHA for 99d769d
Fizz Buzz/FizzBuzz.swift
@@ -1,19 +1,21 @@
1
-func fizzBuzz(_ numberOfTurns: Int) {
2
- for i in 1...numberOfTurns {
3
- var result = ""
+// Updated for Xcode Version 11.4.1 (11E503a)
4
5
- if i % 3 == 0 {
6
- result += "Fizz"
+func fizzBuzz2(_ numberOfTurns: Int) {
+ guard numberOfTurns >= 1 else {
+ print("Number of turns must be >= 1")
+ return
7
}
8
-
9
- if i % 5 == 0 {
10
- result += (result.isEmpty ? "" : " ") + "Buzz"
11
- }
12
13
- if result.isEmpty {
14
- result += "\(i)"
+
+ for i in 1...numberOfTurns {
+ switch (i.isMultiple(of: 3), i.isMultiple(of: 5)) {
+ case (false, false):
+ print("\(i)")
+ case (true, false):
+ print("Fizz")
15
+ case (false, true):
16
+ print("Buzz")
17
+ case (true, true):
18
+ print("Fizz Buzz")
19
+ }
20
- print(result)
21
0 commit comments