Created
November 4, 2019 03:55
-
-
Save fmo91/af61b40ea283a49c0f4e16483a998609 to your computer and use it in GitHub Desktop.
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
struct Product { | |
// ... | |
let price: Double | |
} | |
class ProductsCalculator { | |
private var products: [Product] = [] | |
func add(product: Product) { | |
products.append(product) | |
} | |
func calculateTotal() -> Double { | |
let subtotal = products.map({ $0.price }).reduce(0, +) | |
return applyTaxes(to: subtotal) | |
} | |
private func applyTaxes(to subtotal: Double) -> Double { | |
// Some weird taxes logic 😨 | |
subtotal * 1.21 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment