mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-17 09:59:10 +00:00
chore: move src/common/utils to @roleypoly/misc-utils
This commit is contained in:
parent
a374030438
commit
65a8760e86
36 changed files with 38 additions and 465 deletions
48
packages/misc-utils/sortBy.spec.ts
Normal file
48
packages/misc-utils/sortBy.spec.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { sortBy } from './sortBy';
|
||||
|
||||
it('sorts an array of objects by its key', () => {
|
||||
const output = sortBy(
|
||||
[
|
||||
{
|
||||
name: 'bbb',
|
||||
},
|
||||
{
|
||||
name: 'aaa',
|
||||
},
|
||||
{
|
||||
name: 'ddd',
|
||||
},
|
||||
{
|
||||
name: 'ccc',
|
||||
},
|
||||
],
|
||||
'name'
|
||||
);
|
||||
|
||||
expect(output.map((v) => v.name)).toEqual(['aaa', 'bbb', 'ccc', 'ddd']);
|
||||
});
|
||||
|
||||
it('sorts an array of objects by its key with a predicate', () => {
|
||||
const output = sortBy(
|
||||
[
|
||||
{
|
||||
name: 'cc',
|
||||
},
|
||||
{
|
||||
name: 'bbb',
|
||||
},
|
||||
{
|
||||
name: 'aaaa',
|
||||
},
|
||||
{
|
||||
name: 'd',
|
||||
},
|
||||
],
|
||||
'name',
|
||||
(a, b) => {
|
||||
return a.length > b.length ? 1 : -1;
|
||||
}
|
||||
);
|
||||
|
||||
expect(output.map((v) => v.name)).toEqual(['d', 'cc', 'bbb', 'aaaa']);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue