5 kyu

Deep comparison of objects

1,026opensas

Description:

Comparing objects is not an easy task in JavaScript. The comparison operator only returns true if both variables point to the same object, that's why two objects with the same properties and values are different for JavaScript, like this:

var a = { name: 'Joe' };
var b = { name: 'Joe' };
a == b;  //-> false

Sometimes it's really useful to detect when two objects have the same values.

Your task is to develop the deepCompare function to test if two objects have the same properties and values. Remember that an object can contain other objects. The function should also be able to correctly compare simple values, like strings and numbers (without using type coercion, please).

To make things simpler, it will only have to deal with simple values and objects and arrays containing strings, booleans and numbers, without taking into account regular expressions, dates and functions.

Fundamentals

More By Author:

Check out these other kata created by opensas

Stats:

CreatedJul 13, 2014
PublishedJul 13, 2014
Warriors Trained2971
Total Skips571
Total Code Submissions25242
Total Times Completed1026
JavaScript Completions1026
Total Stars92
% of votes with a positive feedback rating85% of 147
Total "Very Satisfied" Votes110
Total "Somewhat Satisfied" Votes29
Total "Not Satisfied" Votes8
Ad
Contributors
  • opensas Avatar
  • OverZealous Avatar
  • JohanWiltink Avatar
Ad