mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-15 00:59:09 +00:00
parent
175144cc7a
commit
dec4aa9619
4 changed files with 4 additions and 32 deletions
|
@ -19,25 +19,3 @@ 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