Last active
November 17, 2021 21:35
-
-
Save themgoncalves/ce2493408b77017814cc1edf4f5186dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import typeOf from './type-of'; | |
| const shallowCompare = (source, target) => { | |
| if (typeOf(source) !== typeOf(target)) { | |
| return false; | |
| } | |
| if (typeOf(source) === 'array') { | |
| return source.length === target.length; | |
| } else if (typeOf(source) === 'object') { | |
| return Object.keys(source).every((key) => source[key] === target[key]); | |
| } else if (typeOf(source) === 'date') { | |
| return source.getTime() === target.getTime(); | |
| } | |
| return source === target; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This logic doesn't look correct
will return true...