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 sumOfTwoSmallestIntegersIn(_ array: [Int]) -> Int { | |
let smallArray = array.sorted() | |
var firstNum = smallArray[0] | |
var secondNum = smallArray[1] | |
return firstNum + secondNum | |
} | |
sumOfTwoSmallestIntegersIn([19, 5, 42, 2, 77]) |
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
var counties = ["Franklin": [43215, 43213, 43219, 43227, 43228], "Delaware": [43015, 43035, 43003, 43061, 43065], "Pickaway": [43113, 43103, 43116, 43117, 43156]] | |
for zipCode in counties.values { | |
print("Ohio has the following zip codes: \(zipCode)") | |
} |
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
var toDoList = ["Take out garbage", "Pay bills", "Cross off finished items"] | |
for _ in toDoList { | |
toDoList.reverse() | |
print(toDoList) | |
} |
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 great(_ name: String, _ owner: String) -> String { | |
// complete this function | |
if name == owner { | |
return("Hello boss") | |
} | |
else { | |
return("Hello guest") | |
} | |
} |
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
var i: Int = 3 | |
var fizz: String = "Fizz" | |
var buzz: String = "Buzz" | |
var fizzBuzz: String = "FizzBuzz" | |
for i in 1...100 where i % 3 == 0 { | |
print(fizz) | |
} | |
for i in 1...100 where i % 5 == 0 { |
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 switchItUp (_ number: Int) -> String { | |
switch number { | |
case 0: | |
return "Zero" | |
case 1: | |
return "One" | |
case 2: | |
return "Two" | |
case 3: |
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 RentalCarCost(_ days: Int) -> Int { | |
let costPerDay = 40 | |
var totalCost = costPerDay * days | |
if (days >= 7) { | |
totalCost -= 50 | |
} | |
else if (days >= 3) { | |
totalCost -= 20 |
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 bmi(_ weight: Int, _ height: Double) -> String { | |
let bmi = Double(weight) / (height * height) | |
if (bmi <= 18.5) { | |
return "Underweight" | |
} | |
else if (bmi <= 25.0) { |