JavaScript (ES6) - Algorithms - (deepEquals) - check if two objects are equal

preview_player
Показать описание
I code out the following function...
deepEquals -
is a function that takes 2 objects and returns true if they are both equal and false if they are not. Objects in Javascript cannot be compared with the '===';

language: JavaScript ES6

-----
If you have any questions, or comments, or suggestions, or if I made any errors, please let me know!
Рекомендации по теме
Комментарии
Автор

First example, time complexity: Considering JSON.stringify() has to go through each property, it should at least be O(n).
Space complexity: Should be O(1). I’d imagine JSON.stringify() uses for loops internally, and each loop would re use space for a counter variable.

Second example, time complexity: O(n), since for in goes through each property of each object.
Space complexity: Should be O(1). For loop re-uses key variable.

This is from my recollection of a CS lecture ~6 years ago, so I definitely could be wrong.

albertolinguini
Автор

Can you explain why you recurse with the !deepEquals instead of just recursing normally? From what I can understand, you're trying to achieve a false return quicker but I don't quite understand what the program is doing with the if (!deepEquals(a[key], b[key]) line. I wrote a similar program, but I just recurse normally without the ! and it still works. Can you expand on this a bit further? Thanks for the great videos.

YouJordnz
Автор

which editor you are using, which compiles the scripts siimantaneously

naturevibes
Автор

Is deepEquals part of ES6 or is it a 3th party module?

fristytron