Last active
October 15, 2019 22:51
-
-
Save ericlmartinezo/a36adb7247cfbdaaf636da54aaaa1157 to your computer and use it in GitHub Desktop.
Stupid code paring part 2
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
// Here's a swifty way for dealing with multiples of | |
// First you pass the range of numbers you want irriate through | |
// Create a forEach loop that will loop cases in your Switch | |
// Switch will always en with Default. | |
// These can be done in many ways but the trick is to use the functions Swift provides. In this case isMultiple | |
(1...15).forEach { (number) in | |
switch number { | |
case let x where x.isMultiple(of: 15): | |
print("FizzBuzz") | |
case let x where x.isMultiple(of: 3): | |
print("\(number): Buzz") | |
case let x where x.isMultiple(of: 5): | |
print("\(number): Fizz") | |
default: | |
print(number) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment