Improved deep equality testing for Node.js and the browser with support for complex types and circular references.
Overall
score
96%
Build a validation system that compares user profile objects from different sources to ensure they represent the same user. The system should determine if two profile objects are equivalent based on their data content, regardless of how they were created.
Your application receives user profile data from multiple sources (API responses, database records, cached data, etc.). These sources may create profile objects using different constructors or classes, but you need to identify when they represent the same user with the same information.
Implement a function areProfilesEqual(profile1, profile2) that:
true if two profile objects contain the same data valuesTwo profiles with identical properties (name: "Alice", age: 30, email: "alice@example.com") created from the same class should be equal @test
Two profiles with identical properties (name: "Bob", age: 25, email: "bob@example.com") created from different classes should be equal @test
Two profiles with different property values (profile1: {name: "Alice", age: 30}, profile2: {name: "Alice", age: 31}) should not be equal @test
Two profiles with nested address objects (address: {street: "123 Main St", city: "Boston"}) should be equal if the nested objects match @test
@generates
/**
* Compares two user profile objects for equality based on their data content.
*
* @param {Object} profile1 - The first profile object to compare
* @param {Object} profile2 - The second profile object to compare
* @returns {boolean} True if profiles contain equivalent data, false otherwise
*/
function areProfilesEqual(profile1, profile2) {
// Implementation
}
module.exports = { areProfilesEqual };Provides deep equality comparison with support for comparing class instances.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-deep-eqldocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10