chore: move src/common/utils to @roleypoly/misc-utils

This commit is contained in:
41666 2021-03-12 16:54:08 -05:00
parent a374030438
commit 65a8760e86
36 changed files with 38 additions and 465 deletions

View file

@ -0,0 +1,21 @@
export const sortBy = <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;
});
};