-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rooms sorted by favorites first
- Loading branch information
1 parent
34073c7
commit 6d0684e
Showing
4 changed files
with
47 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { sortByFavoritedAndName } from './arrayUtils'; | ||
|
||
const testArray = [ | ||
{ name: 'a', favorited: false }, | ||
{ name: 'b', favorited: true }, | ||
{ name: 'c', favorited: false } | ||
]; | ||
describe('isNonEmptyArray', () => { | ||
test('Should return false for null', () => { | ||
expect(sortByFavoritedAndName(testArray)).toEqual([ | ||
{ name: 'b', favorited: true }, | ||
{ name: 'a', favorited: false }, | ||
{ name: 'c', favorited: false } | ||
]); | ||
}); | ||
}); |
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,10 @@ | ||
export function sortByFavoritedAndName<T>( | ||
array: { name: string; favorited: boolean }[] | ||
): T[] { | ||
return array.sort((a, b) => { | ||
if (a.favorited === b.favorited) { | ||
return a.name.localeCompare(b.name); | ||
} | ||
return a.favorited ? -1 : 1; | ||
}) as T[]; | ||
} |