Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
relf committed Nov 7, 2019
1 parent a40bf3f commit f2bce56
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/javascript/utils/compare.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function deepIsEqual(first, second) {
// If first and second are the same type and have the same value
// Useful if strings or other primitive types are compared
if (first === second) return true;
if (first === second) { return true; }

// Try a quick compare by seeing if the length of properties are the same
const firstProps = Object.getOwnPropertyNames(first);
const secondProps = Object.getOwnPropertyNames(second);

// Check different amount of properties
if (firstProps.length !== secondProps.length) return false;
if (firstProps.length !== secondProps.length) { return false; }

// Go through properties of first object
for (let i = 0; i < firstProps.length; i += 1) {
Expand All @@ -17,15 +17,15 @@ function deepIsEqual(first, second) {
switch (typeof (first[prop])) {
// If it is an object, decend for deep compare
case 'object':
if (!deepIsEqual(first[prop], second[prop])) return false;
if (!deepIsEqual(first[prop], second[prop])) { return false; }
break;
case 'number':
// with JavaScript NaN != NaN so we need a special check
// eslint-disable-next-line no-restricted-globals
if (isNaN(first[prop]) && isNaN(second[prop])) break;
if (isNaN(first[prop]) && isNaN(second[prop])) { break; }
// eslint-disable-next-line no-fallthrough
default:
if (first[prop] !== second[prop]) return false;
if (first[prop] !== second[prop]) { return false; }
}
}
return true;
Expand Down

0 comments on commit f2bce56

Please sign in to comment.