Handle sorting with undefined values
All checks were successful
Build / Publish Docs (push) Successful in 47s
Build / Build NPM Project (push) Successful in 1m4s
Build / Tag Version (push) Successful in 10s

This commit is contained in:
2025-12-13 00:27:47 -05:00
parent 49959f3060
commit 3048b74b2f
3 changed files with 8 additions and 1 deletions

View File

@@ -122,6 +122,8 @@ export function sortByProp(prop: string, reverse = false) {
return function (a: any, b: any) {
const aVal = dotNotation<any>(a, prop);
const bVal = dotNotation<any>(b, prop);
if(aVal === undefined) return 1;
if(bVal === undefined) return -1;
if(typeof aVal == 'number' && typeof bVal == 'number')
return (reverse ? -1 : 1) * (aVal - bVal);
if(aVal > bVal) return reverse ? -1 : 1;