Skip to content
Advertisement

Deep copy object with Depth-First Search

I trying to copy an object. I want to made it with algorithm Depth-First Search.

JavaScript

I create a function which will be copy my object without links on old objects. I have a problem, my function doesn’t count the result correctly. Where do i make a mistake?

Advertisement

Answer

dfs without recursion use additional stack to track parent properties.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement