File tree Expand file tree Collapse file tree 1 file changed +9
-16
lines changed Expand file tree Collapse file tree 1 file changed +9
-16
lines changed Original file line number Diff line number Diff line change 11//deep comparison of multi-dimensional arrays with recursion
22
33const deepCompare = ( a , b ) => {
4- let res = true
4+ if ( a === b ) return true
55
6- if ( Array . isArray ( a ) && Array . isArray ( b ) )
6+ if ( typeof a === "object" && typeof b === "object" )
77 {
8- let count = 0 ;
9-
10- while ( res && count < a . length )
8+ if ( a instanceof Date && b instanceof Date ) return a . valueOf ( ) === b . valueOf ( )
9+ else
1110 {
12- res = ! a . some ( ( val , i ) => {
13- return ! deepCompare ( val , b [ i ] )
11+ const keysA = Object . keys ( a )
12+ if ( keysA . length !== Object . keys ( b ) . length ) return false
13+ return ! keysA . some ( key => {
14+ return ! deepCompare ( a [ key ] , b [ key ] )
1415 } )
15-
16- count ++
1716 }
1817 }
19- else
20- {
21- res = ( a === b )
22- }
23-
24- return res
25-
18+ else return false
2619}
You can’t perform that action at this time.
0 commit comments