Skip to content

Instantly share code, notes, and snippets.

@adriatikgashi
Created February 27, 2022 17:49
Show Gist options
  • Save adriatikgashi/1a373a1cf0e5605a984f4cf456de34b6 to your computer and use it in GitHub Desktop.
Save adriatikgashi/1a373a1cf0e5605a984f4cf456de34b6 to your computer and use it in GitHub Desktop.
struct Order {
let lineItems: [String]
let shipping: String
func getShippingCost() -> Double {
if shipping == "ground" {
if getTotal() > 100 {
return 0
}
// $1.5 per kilogram, but $10 minimum
return max(10, getTotalWeight() * 1.5)
}
if shipping == "air" {
return max(20, getTotalWeight() * 3)
}
return 0.0
}
func getTotal() -> Double {
// calculate the total
return 0.0
}
func getTotalWeight() -> Double {
// calculate the total weight
return 0.0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment