-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Max Einstein
committed
Jun 23, 2017
1 parent
8c3ba65
commit 0933445
Showing
8 changed files
with
50 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
const isEqual = (a, b) => { | ||
Object.keys(a).forEach(key => { | ||
if (typeof b[key] === 'undefined') { | ||
return false | ||
} | ||
export default function(a, b) { | ||
// grab keys of respective objects | ||
const aKeys = Object.keys(a) | ||
const bKeys = Object.keys(b) | ||
|
||
// if two empty objects | ||
if (aKeys.length === 0 && bKeys.length === 0) { | ||
return true | ||
} | ||
|
||
// if lengths are different | ||
if (aKeys.length !== bKeys.length) { | ||
return false | ||
} | ||
|
||
for (const key of aKeys) { | ||
if (a[key] !== b[key]) { | ||
return false | ||
} | ||
}) | ||
} | ||
|
||
return true | ||
} | ||
|
||
export default isEqual |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// local imports | ||
import isEqual from './is-equal' | ||
|
||
describe('utils', () => { | ||
describe('isEqual()', () => { | ||
|
||
test('two empty objects', () => { | ||
const res = isEqual({}, {}) | ||
expect(res).toEqual(true) | ||
}) | ||
|
||
test('two objects with diff num of keys', () => { | ||
const res = isEqual({a: 2, b: 1}, {a: 2}) | ||
expect(res).toEqual(false) | ||
}) | ||
|
||
test('two objects with same keys/props in diff order', () => { | ||
const res = isEqual({a: 2, b: 1}, {b: 1, a: 2}) | ||
expect(res).toEqual(true) | ||
}) | ||
}) | ||
}) |