Update top JS snippets

This commit is contained in:
Chalarangelo
2021-10-13 20:09:28 +03:00
parent 2b775e3c93
commit 3cd481c0d1
19 changed files with 45 additions and 43 deletions

View File

@ -2,12 +2,14 @@
title: equals
tags: object,array,type,recursion,advanced
firstSeen: 2018-01-15T18:34:11+02:00
lastUpdated: 2021-09-08T09:37:36+03:00
lastUpdated: 2021-10-13T19:29:39+02:00
---
Performs a deep comparison between two values to determine if they are equivalent.
- Check if the two values are identical, if they are both `Date` objects with the same time, using `Date.prototype.getTime()` or if they are both non-object values with an equivalent value (strict comparison).
- Check if the two values are identical.
- Check if both values are `Date` objects with the same time, using `Date.prototype.getTime()`.
- Check if both values are non-object values with an equivalent value (strict comparison).
- Check if only one value is `null` or `undefined` or if their prototypes differ.
- If none of the above conditions are met, use `Object.keys()` to check if both values have the same number of keys.
- Use `Array.prototype.every()` to check if every key in `a` exists in `b` and if they are equivalent by calling `equals()` recursively.