Skip to content

Instantly share code, notes, and snippets.

@ericlmartinezo
Last active October 15, 2019 22:51
Show Gist options
  • Save ericlmartinezo/a36adb7247cfbdaaf636da54aaaa1157 to your computer and use it in GitHub Desktop.
Save ericlmartinezo/a36adb7247cfbdaaf636da54aaaa1157 to your computer and use it in GitHub Desktop.
Stupid code paring part 2
// 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