-
Notifications
You must be signed in to change notification settings - Fork 149
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
1 parent
2b4dc3a
commit fc86d2f
Showing
4 changed files
with
73 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const BreakException = {} | ||
|
||
export default function arrayObjectsEqual (array1, array2) { | ||
let equal = array1.length === array2.length | ||
|
||
if (!equal) { | ||
return equal | ||
} | ||
|
||
try { | ||
array1.every(function(value, index) { | ||
if (JSON.stringify(value) !== JSON.stringify(array2[index])) { | ||
throw BreakException | ||
} | ||
}) | ||
} catch (e) { | ||
/* istanbul ignore else */ | ||
if (e === BreakException) { | ||
equal = false | ||
} else { | ||
throw e | ||
} | ||
} | ||
|
||
return equal | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import arrayObjectsEqual from './../../../src/utils/arrayObjectsEqual' | ||
|
||
describe('arrayObjectsEqual', () => { | ||
it('should return false if arrays are not same length', () => { | ||
expect(arrayObjectsEqual([1],[1,2])).toBe(false) | ||
}) | ||
}) |