Skip to content

Commit

Permalink
add numberSorterWithInfinityValue
Browse files Browse the repository at this point in the history
  • Loading branch information
yomybaby committed May 27, 2024
1 parent f93c982 commit d232e78
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions react/src/helper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,17 @@ export function transformSorterToOrderString<T = any>(
: undefined;
}
}

export const numberSorterWithInfinityValue = (
a?: number | null,
b?: number | null,
infiniteValue?: number | null,
nullishFallbackValue: number = 0,
) => {
const transform = (value?: number | null) => {
if (value === infiniteValue) return Number.POSITIVE_INFINITY;
if (value === null || value === undefined) return nullishFallbackValue;
return value;
};
return transform(a) - transform(b);
};

0 comments on commit d232e78

Please sign in to comment.