1050. JSON Deep Equal
Give two values, o1 and o2, and return a boolean value that indicates if they are deeply equal.
Two values must satisfy the following requirements in order to be deeply equal:
- If two values satisfy the === equality check, they are deeply equal if they are primitive types.
- If both values are arrays and contain the same items in the same order, then they are deeply equal. If these conditions are met, then each element is also deeply equal.
- In the event that both values are objects, they are deeply equal if they share keys, and if each key's associated values meet these requirements, they are also deeply equal.
You may assume both values are the output of JSON.parse. In other words, they are valid JSON.
Please solve it without using lodash's _.isEqual() function
Example 1:
Input : o1 = {"x":{"z":"value"},"L":[1,2,3]}, o2 = {"x":{"z":"value"},"L":[1,2,3]}
Output : true
Explanation : The keys and values matches exactly.
Example 2:
Input : o1 = {"x":{"z":"value2"},"L":[1,2,3]}, o2 = {"x":{"z":"value"},"L":["1","2","3"]}
Output : false
Explanation :
The value of the keys "z" dos not match in both the objects.
The array of numbers is different from the array of strings
Now Your Turn!
Pick the correct output for the given inputInput : o1 = true , o2 = false
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= JSON.stringify(o1).length <= 105
- 1 <= JSON.stringify(o2).length <= 105
- maxNestingDepth <= 100