DEV Community

Discussion on: Favorite Front-end/UI developer interview questions?

Collapse
 
salyadav profile image
Saloni Yadav

I was given an object and asked to create a copy.
I happily said Object.assign...
So these there the follow ups that screwed me over-

  1. What if it has nested objects, then Object.assign wont deep clone it. (where i answered with a loop to resolve this issue)
  2. What if there is a cyclic dependency? (I was stuck, but the interviewer insinuated to the tortoise-hare algo of two pointer solution to crack the cyclic dependency, although i still dont think that will help).

Note- I was to answer in VanillaJS, so answers like Lodash deep clone wouldnt work.
Anyways, I went back and learnt a lot while exploring this concept.