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
+28-3Lines changed: 28 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -595,12 +595,31 @@ if(a === b) return true
595
595
596
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.
597
597
598
-
Next, we can process the dates first, as that doesn't require iteration. Make sure to compare ```Date.valueOf()``` instead.
598
+
```if(typeof a ==="object"&&typeof b ==="object")...```
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.
601
+
602
+
```if(a instanceofDate&& b instanceofDate) returna.valueOf() ===b.valueOf()```
599
603
600
604
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.
601
605
606
+
```constkeysA=Object.keys(a) //get keys/index of object/array
607
+
if(keysA.length!==Object.keys(b).length) returnfalse//make sure a and b are same length
608
+
609
+
//Array.some stops executing nested code the moment there is one different value
0 commit comments