How to add (math) two maps?

Hello. I have two maps with the same structure: enum(key) and float(value). If I want to add them, how can I do this?
Example:
(Head: 0.1; Body: 0.3; Legs: 0.2) + (Head: 0.3; Body: 0.2; Legs: 0.1) = (Head: 0.4; Body: 0.5; Legs: 0.3)

1 Like

For each key in map1, you update the same key in map2 with the sum of the floats.

Map 2 here, ends up with the sum.

You might want to put it in a third map.

But this will miss out keys from map2, if they are not in map1.

2 Likes

Well, the first solution is exactly what I needed. I’m always find it by myself but I was confused with “If something already uses the provided key it will be overwritten with the new value” phrase in documentation. So I’ve finished with 5 maps…

2 Likes