Answer the question
In order to leave comments, you need to log in
How to merge two dictionaries?
Merge the two dictionaries into one called tables. If both dictionaries have the same key, sum the values. !!!Use only dictionaries and arrays
let table1 = ["box":3, "lamp":1, "pen":2]
let table2 = ["box":2, "PC":1, "pen": 3]
Answer the question
In order to leave comments, you need to log in
let table1 = ["box": 3, "lamp": 1, "pen": 2]
let table2 = ["box": 2, "PC": 1, "pen": 3]
let table = table1.merging(table2) { $0 + $1 }
// ["pen": 5, "lamp": 1, "PC": 1, "box": 5]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question