bugger.
All challenges/TypeScriptmediumthe-aliases-that-repeat-the-work-v1
THE INVESTIGATION

The aliases that repeat the work

Repeated aliases produce the right merged data while multiplying unnecessary work.

Real incidentsAlgorithmic complexityRegression testing

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

01 Repeated alias repeats key scans
[{"sources":[{"a":1,"b":2}],"merges":[{"ids":[0,0,0],"own":{}}]}]
[[{"value":{"a":1,"b":2},"work":2}]]
02 Distinct sources control
[{"sources":[{"a":1},{"b":2}],"merges":[{"ids":[0,1],"own":{}}]}]
[[{"value":{"a":1,"b":2},"work":2}]]
03 Own properties win control
[{"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.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.