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
+50-4Lines changed: 50 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -593,14 +593,45 @@ 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
-
Next, we can process the dates first, as that doesn't require iteration. Make sure to compare ```Date.valueOf()``` instead.
598
+
```js
599
+
if(typeof a ==="object"&&typeof b ==="object")...
600
+
```
601
+
602
+
Note that we use ```===``` here to differentiate between data types strictly.
603
+
604
+
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.
605
+
606
+
```js
607
+
if(a instanceofDate&& b instanceofDate) returna.valueOf() ===b.valueOf()
608
+
```
599
609
600
610
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.
0 commit comments