Kat H.

asked • 10/06/21

Create a function based on Deep Equality called deepEqual that takes two arguments 'true' and 'false'

Javascript. Create a function based on Deep Equality called deepEqual that takes two arguments 'true' and 'false' and returns true if the arguments are deep equal and false if the arguments are not deep equal. All the code is provided, just please create the deepEqual function based on the Deep Equality definition.


Definition of Deep Equality


Case 1. If two values are primitive and are strictly equal, then they are deep equal.

Case 2: If two values are primitive and are not strictly equal, then they are not deep equal.

Case 3. If one value is an object and the other value is primitive, then they are not deep equal.

Case 4: If two values are both objects and are strictly equal, then they are deep equal.

Case 5: If two values are both objects and are not strictly equal, then we determine deep equality as follows:

5.1 If both values are non-array objects, then they are deep equal if both the objects have exactly the same properties and the values of these properties are deep equal. The order of properties in these non-array objects doesn't matter for deep equality.

5.2 If both values are arrays, then they are deep equal if their elements are deep equal and these elements are in the same order.

5.3 All other pairs of objects are not deep equal.

Please have the function handle numbers, boolean values, strings, null values, undefined values, and objects, including arrays.



Code:


'use strict';

// Don't add or change anything above this comment.

/*

* Don't change the declaration of this function.

*/

function deepEqual(val1, val2) {

}

// Don't add or change anything below this comment.

module.exports = deepEqual;


1 Expert Answer

By:

David V. answered • 05/01/22

Tutor
0 (0)

Software Engineering (HTML, CSS, React, Ruby on Rails) Tutor

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.