CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-deep-eql

Improved deep equality testing for Node.js and the browser with support for complex types and circular references.

Overall
score

96%

Overview
Eval results
Files

task.mdevals/scenario-5/

User Profile Validator

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.

Background

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.

Requirements

Implement a function areProfilesEqual(profile1, profile2) that:

  1. Returns true if two profile objects contain the same data values
  2. Compares profiles based on their property values, not their constructors or prototypes
  3. Handles profiles that may be instances of different classes but have identical properties
  4. Performs deep comparison for nested objects within profiles
  5. Considers profiles equal even if they were created from different class constructors

Test Cases

  • Two 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

Implementation

@generates

API

/**
 * 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 };

Dependencies { .dependencies }

deep-eql { .dependency }

Provides deep equality comparison with support for comparing class instances.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-deep-eql

tile.json