Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/utils/src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ export const orderArrayBy = (orgArray: any[], key: string, ordering: "ascending"
const innerKey = key.split("."); // split the key by dot

return array.sort((a, b) => {
const keyA = innerKey.reduce((obj, i) => obj[i], a); // get the value of the inner key
const keyB = innerKey.reduce((obj, i) => obj[i], b); // get the value of the inner key
const keyA = innerKey.reduce((obj, i) => obj?.[i], a); // get the value of the inner key
const keyB = innerKey.reduce((obj, i) => obj?.[i], b); // get the value of the inner key

// Handle undefined/null values - push them to the end
if (keyA == null && keyB == null) return 0;
if (keyA == null) return 1;
if (keyB == null) return -1;

if (keyA < keyB) {
return ordering === "ascending" ? -1 : 1;
}
Expand Down