The aliases that repeat the work
Repeated aliases produce the right merged data while multiplying unnecessary work.
What’s going wrong
Input is an array of at most 100 {sources, merges} rows. sources contains at most 40 flat objects with at most 40 scalar-valued own properties each. Keys never equal __proto__, constructor or prototype. Each merges entry is {ids, own}; ids contains at most 100 valid zero-based source indices, and own is a flat object. The same index denotes the SAME source object; different indices denote distinct objects even when their contents are equal. For each merge, retain own properties, then fill missing properties from sources in ids order (first source wins). Process each source identity only once PER merge destination. Return {value, work} for each merge, where work counts every inspected own source key on its first occurrence, even if the key was already present in value. Return one array of merge results per input row. Do not use elapsed time as the oracle.
Expected behavior
Bound redundant merge work by source identity.
Reproduction
[{"sources":[{"a":1,"b":2}],"merges":[{"ids":[0,0,0],"own":{}}]}][[{"value":{"a":1,"b":2},"work":2}]][{"sources":[{"a":1},{"b":2}],"merges":[{"ids":[0,1],"own":{}}]}][[{"value":{"a":1,"b":2},"work":2}]][{"sources":[{"a":1,"b":2}],"merges":[{"ids":[0],"own":{"a":9}}]}][[{"value":{"a":9,"b":2},"work":2}]]Before you begin
- TypeScript objects and Sets
- Algorithmic complexity and object identity
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.