mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-15 00:59:09 +00:00
flip role order
This commit is contained in:
parent
a682ade1d3
commit
175144cc7a
4 changed files with 32 additions and 4 deletions
|
@ -19,3 +19,25 @@ export const sortBy = <T, Key extends keyof T>(
|
|||
return -1;
|
||||
});
|
||||
};
|
||||
|
||||
export const sortByReverse = <T, Key extends keyof T>(
|
||||
array: T[],
|
||||
key: Key,
|
||||
predicate?: (a: T[typeof key], b: T[typeof key]) => number
|
||||
) => {
|
||||
return array.sort((a, b) => {
|
||||
if (predicate) {
|
||||
return predicate(a[key], b[key]);
|
||||
}
|
||||
|
||||
if (a[key] === b[key]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (a[key] > b[key]) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue