Is it time-intensive to copy objects? For example, if I want to build a map counting occurrences in an array, I thought of doing this:
const addToMap = (map, e) => Object.assign({}, map, { [e]: (map[e] || 0) + 1 });
const buildMap = a => a.reduce(addToMap, {});
I wanted to create a pure, single-purpose function, instead of having addToMap mutate the object as a side effect. The trade-off though is that it has to copy the object everytime. I don't think this is a memory concern, but does it take a long time to copy a large object?