我查看了StackOverflow,但沒有找到任何說明在字典中採用特定Int或Double的平均值的地方。這是我創建的自定義字典:Swift - 以字典的元素的平均值
var allInformationByDate = [
"1989-06-20": DayData(sales: 0, doorsKnocked: 0, milesWalked: 0.00, hoursWorked: 0.00),
"2016-06-22": DayData(sales: 2, doorsKnocked: 30, milesWalked: 2.00, hoursWorked: 3.00),
"2016-08-16": DayData(sales: 4, doorsKnocked: 30, milesWalked: 10.00, hoursWorked: 0.00)
]
所以我會尋找獲得這些每個的平均值。例如:
var avgSales = average(sales) = 2
var avgDoors = average(doorsKnocked) = 20
var avgMiles = average(milesWalked) = 4.0
var avgHours = average(hoursWorked) = 1.0
有人知道語法嗎?感謝您幫助noob!