mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-15 09:09:10 +00:00
Fix role ordering (#789)
* fix role order in picker * one of these sorts will flip it omg * fix role list * revert forced role sort in api
This commit is contained in:
parent
33a8a0048f
commit
45a1f45055
4 changed files with 21 additions and 18 deletions
|
@ -1,8 +1,11 @@
|
|||
export const sortBy = <T, Key extends keyof T>(
|
||||
array: T[],
|
||||
key: Key,
|
||||
predicate?: (a: T[typeof key], b: T[typeof key]) => number
|
||||
predicate?: (a: T[typeof key], b: T[typeof key]) => number,
|
||||
reverse?: boolean
|
||||
) => {
|
||||
let postmultiplier = reverse ? -1 : 1;
|
||||
|
||||
return array.sort((a, b) => {
|
||||
if (predicate) {
|
||||
return predicate(a[key], b[key]);
|
||||
|
@ -13,9 +16,9 @@ export const sortBy = <T, Key extends keyof T>(
|
|||
}
|
||||
|
||||
if (a[key] > b[key]) {
|
||||
return 1;
|
||||
return 1 * postmultiplier;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1 * postmultiplier;
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue