2
試圖將字典中的整數加在一起。例如:將字典中的整數加在一起
var dictionary = ["one": 1, "two": 2, "three": 3, "four": 4, "five": 5]
我希望得到的總和1 + 2 + 3 + 4 + 5 = 15
我理解它可能會需要一個循環像
for (n, i) in dictionary {
*some math function*
}
任何幫助將不勝感激,也許我只是在想這個?
[ 「A」:1, 「B」:2, 「C」:3] .MAP {$ 1}。降低(0,combine:+) –
@ChristianDietrich,只看到我的版本縮短而已。 – Sandeep
這似乎不適合我。我的字典類型沒有名爲reduce的成員。 – iNick