Hi Greg
the code provided in challenge is very confusing. can u pls explain with more comments as i am totally loat in the solution provided. pls find the code pasted below .can u please explain it with more comments or provide a simpler solution as it is very confusing for a beginner like me.
// Key = restaurant name, value = total
var totalsByRestaurant: [String: Double] = [:]
// loop through all restaurant bills
for bill in restaurantBills {
if let thisTotal = totalsByRestaurant[bill.restaurant.name] {
// there's already a total for this restaurant!
totalsByRestaurant[bill.restaurant.name] = thisTotal + bill.totalBill + bill.calculateTip()
} else {
// this is the first time seeing this restaurant in the dictionary
totalsByRestaurant[bill.restaurant.name] = bill.totalBill + bill.calculateTip()
}
}
// show the results
for (restaurantName, total) in totalsByRestaurant {
print("The total spent at \(restaurantName): $\(total)")
}