You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-9Lines changed: 25 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -593,23 +593,30 @@ Firstly, we'll do the most simple check of ```a === b``` to avoid unnecessary co
593
593
if(a === b) returntrue
594
594
```
595
595
596
-
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.
596
+
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 b are of type object. If not, we can just return false as they didn't pass the ```a===b``` test.
597
597
598
598
```jsif(typeof a ==="object"&&typeof b ==="object")...```
599
599
600
-
Next, we can process the dates first, as that doesn't require iteration. Make sure to compare ```Date.valueOf()``` instead of the date itself.
600
+
Note that we use ```===``` here to differentiate between data types strictly.
601
+
602
+
Next, we can process the dates first, as that doesn't require iteration. Make sure to compare ```Date.valueOf()``` instead of the date object itself.
601
603
602
604
```jsif(a instanceofDate&& b instanceofDate) returna.valueOf() ===b.valueOf() ```
603
605
604
606
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.
605
607
606
608
```js
607
-
constkeysA=Object.keys(a) //get keys/index of object/array
608
-
if(keysA.length!==Object.keys(b).length) returnfalse//make sure a and b are same length
0 commit comments