Skip to content

Sorting objects where the field may be null for some #20

@nitinka01

Description

@nitinka01

Can you include a change to treat null/undefined (e.g. missing sort field in few objects from the array being sorted) as a usual value. Currently in such case, the final sorted output seems random.

A quick fix I tried which worked for my case, was to change the comparison line of code as follows, so that the null values appear first for ascending sort and last for descending sort.
comparator = (reducedA||'') > (reducedB||'') ? 1 : -1;

But maybe there is a better or configurable way to achieve it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions