jsartisan / frontend-challenges

FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
https://frontend-challenges.com
20 stars 3 forks source link

Two functions - one object #69

Closed jsartisan closed 1 month ago

jsartisan commented 1 month ago

Info

difficulty: easy
title: Two functions - one object
type: question
template: javascript
tags: javascript, objects

Question

Is it possible to create two constructor functions, A and B, such that new A() is equal to new B() when compared using the == operator?

Given the following setup:

function A() { ... }
function B() { ... }

let a = new A();
let b = new B();

alert(a == b); // true

Provide the implementations for A and B that satisfy the condition a == b.

Template

index.js

export function A() {
   // your code here
}

export function B() {
   // your code here
}

index.test.js

import { A, B } from './';

describe('Constructor Functions A and B', () => {
  test('new A() should equal new B()', () => {
    let a = new A();
    let b = new B();

    expect(a).toBe(b);
  });
});
github-actions[bot] commented 1 month ago

70 - Pull Request updated.