-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
16 changed files
with
4,228 additions
and
2,862 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
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,8 +1,10 @@ | ||
export function arrayEquals(a, b) { | ||
return ( | ||
Array.isArray(a) && | ||
Array.isArray(b) && | ||
a.length === b.length && | ||
a.every((val, index) => val === b[index]) | ||
); | ||
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) { | ||
return false; | ||
} | ||
|
||
const sortedA = a.slice().sort(); | ||
const sortedB = b.slice().sort(); | ||
|
||
return !sortedA.some((val, index) => val !== sortedB[index]); | ||
} |
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,27 @@ | ||
import { arrayEquals } from './array'; | ||
|
||
describe('array', () => { | ||
describe('arrayEquals', () => { | ||
it('should match two arrays based on values, ignoring order', () => { | ||
const array1 = ['jeff', 'fred', 'cecily']; | ||
const array2 = ['fred', 'cecily', 'jeff']; | ||
|
||
const result = arrayEquals(array1, array2); | ||
|
||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
it('should not mutate the original arrays', () => { | ||
const array1 = ['jeff', 'fred', 'cecily']; | ||
const array2 = ['fred', 'cecily', 'jeff']; | ||
|
||
const array1String = array1.toString(); | ||
const array2String = array2.toString(); | ||
|
||
arrayEquals(array1, array2); | ||
|
||
expect(array1.toString()).toBe(array1String); | ||
expect(array2.toString()).toBe(array2String); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.