Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
Develop a program “Object Projection”

I ask for help with solving this problem. I only manage to deal with special cases. Input: any JSON object; prototype object. Output: projected object. Projected object structure shall be intersection of source object and prototype object structures. Values of properties in projected object shall be the same as values of respective properties in source object. For example:

const src = {
    prop11: {
        prop21: 21,
        prop22: {
            prop31: 31,
            prop32: 32
        }
    },
    prop12: 12
};

const proto = {
    prop11: {
        prop22: null
    }
};

This part I was able to do:

const res = (src, proto) => {
    return Object.keys(proto).reduce((a, e) => ({
        ...a, [e]: src[e] ? (proto[e] ? res(src[e], proto[e]) : src[e]) : src[e]
    }), {});
}
console.log(res(src, proto));

We get the following result:

{
  "prop11": {
    "prop22": {
      "prop31": 31,
      "prop32": 32
    }
  }
}

But if the proto is different, for example:

const proto = {
    prop11: {prop21: 1, prop23: null}
};

This solution gives the wrong result. Spent several days on this task already. I would be grateful for any help!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!