Skip to content

Commit be9977f

Browse files
authored
Update README.md
1 parent 98b9267 commit be9977f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -595,21 +595,22 @@ if(a === b) return true
595595
596596
Then comes the interesting part! There are several data types we need to look out for: Objects, Arrays(which JS treats as an object), and Dates(which is also treated as an object!), thus all we have to do is check if both a and is type object. If not, we can just return false as they didn't pass the ```a === b``` test.
597597
598-
```if(typeof a === "object" && typeof b === "object")...```
598+
```js if(typeof a === "object" && typeof b === "object")...```
599599
600600
Next, we can process the dates first, as that doesn't require iteration. Make sure to compare ```Date.valueOf()``` instead of the date itself.
601601
602-
```if(a instanceof Date && b instanceof Date) return a.valueOf() === b.valueOf()```
602+
```js if(a instanceof Date && b instanceof Date) return a.valueOf() === b.valueOf() ```
603603
604604
Lastly, by taking the keys of the iterables we can compare the length of ```a``` and ```b```, then make use of built-in Array.some method to check if any values of the two iterables don't match.
605605
606-
```const keysA = Object.keys(a) //get keys/index of object/array
607-
if(keysA.length !== Object.keys(b).length) return false //make sure a and b are same length
606+
```js
607+
const keysA = Object.keys(a) //get keys/index of object/array
608+
if(keysA.length !== Object.keys(b).length) return false //make sure a and b are same length
608609

609-
//Array.some stops executing nested code the moment there is one different value
610-
return !keysA.some( key => {
611-
return !deepCompare(a[key], b[key]) //run deepCompare recursively
612-
})
610+
//Array.some stops executing nested code the moment there is one different value
611+
return !keysA.some( key => {
612+
return !deepCompare(a[key], b[key]) //run deepCompare recursively
613+
})
613614
```
614615
615616

0 commit comments

Comments
 (0)