bugger.
All challenges/JavaScripthardthe-defaults-that-reach-the-prototype-v1
THE INVESTIGATION

The defaults that reach the prototype

A nested defaults object changes properties on unrelated objects.

Real incidentsPrototype safetyRegression testing

What’s going wrong

Input is {value, defaults}: two JSON objects with scalar leaves (null, strings, booleans or finite numbers), nested objects up to depth 6, and at most 100 keys total. value contains no __proto__, constructor or prototype keys. Apply defaults recursively: preserve every existing own scalar, recursively fill two existing object values, and deep-copy a missing object into value. Never follow inherited properties. Ignore keys named __proto__, constructor or prototype at every depth of defaults; retain all other own keys, including toString and hasOwnProperty. Output {value, prototypeKeys, constructorKeys}; the last two fields are sorted enumerable own keys of Object.prototype and Object and must remain empty. Arrays and undefined values are outside this contract. Each case runs in a fresh process.

Expected behavior

Preserve object ownership across recursive defaults.

Reproduction

01 Constructor reaches a shared prototype
{"value":{},"defaults":{"constructor":{"prototype":{"polluted":true}}}}
{"value":{},"prototypeKeys":[],"constructorKeys":[]}
02 Ordinary nested defaults control
{"value":{"options":{"retries":0}},"defaults":{"options":{"retries":3,"timeout":20}}}
{"value":{"options":{"retries":0,"timeout":20}},"prototypeKeys":[],"constructorKeys":[]}
03 Existing falsey values control
{"value":{"a":false,"b":null,"c":""},"defaults":{"a":true,"b":7,"c":"new"}}
{"value":{"a":false,"b":null,"c":""},"prototypeKeys":[],"constructorKeys":[]}

Before you begin

  • JavaScript own versus inherited properties
  • Recursive object traversal

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.