1 // Function to deep clone an object or array
2 function deepClone(obj
, isFullObject
) {
3 if (typeof obj
!== "object" || obj
=== null) return obj
;
5 const cache
= new Map();
7 const recurse
= (item
) => {
8 if (typeof item
!== "object" || item
=== null) return item
;
10 if (cache
.has(item
)) return cache
.get(item
);
12 const clone
= Array
.isArray(item
)
16 : Object
.create(null);
17 cache
.set(item
, clone
);
19 if (Array
.isArray(item
)) {
20 for (let i
= 0; i
< item
.length
; i
++) {
21 clone
[i
] = recurse(item
[i
]);
24 Object
.keys(item
).forEach((key
) => {
25 clone
[key
] = recurse(item
[key
]);
35 module
.exports
= deepClone
;