File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -92,33 +92,25 @@ function deepCopy(
9292 visitedObjects . set ( value , path ) ;
9393
9494 if ( Array . isArray ( value ) ) {
95- const copy : unknown [ ] = [ ] ;
96-
97- value . forEach ( ( element , index ) => {
98- copy [ index ] = deepCopy (
95+ return value . map ( ( element , index ) =>
96+ deepCopy (
9997 element ,
10098 `${ path } [${ index . toString ( ) } ]` ,
10199 visitedObjects ,
102100 replacer ,
103- ) ;
104- } ) ;
105-
106- return copy ;
101+ ) ,
102+ ) ;
107103 }
108104
109105 const record = value as Record < string , unknown > ;
110- const copy : DecycledObject = { } ;
111-
112- Object . keys ( record ) . forEach ( ( key ) => {
113- copy [ key ] = deepCopy (
114- record [ key ] ,
115- `${ path } [${ JSON . stringify ( key ) } ]` ,
116- visitedObjects ,
117- replacer ,
118- ) ;
119- } ) ;
120106
121- return copy ;
107+ return Object . keys ( record ) . reduce < DecycledObject > ( ( copy , key ) => {
108+ const value = record [ key ] ;
109+ const newPath = `${ path } [${ JSON . stringify ( key ) } ]` ;
110+
111+ copy [ key ] = deepCopy ( value , newPath , visitedObjects , replacer ) ;
112+ return copy ;
113+ } , { } ) ;
122114}
123115
124116/**
You can’t perform that action at this time.
0 commit comments