Skip to content

Unexpected results with falsey data #12

@freakypie

Description

@freakypie
      let sorter = "name";
      let tags = [
        {name: "b"},
        {name: undefined},
        {name: "a"},
        {name: null},
        {name: ""},
        {},
      ];
      console.log("sorting1", tags.map(b => b[sorter]));
      tags.sort(sortby(sorter));
      console.log("sorting2", tags.map(b => b[sorter]));

This is the output I get:

    sorting1 ["b", undefined, "a", null, "", undefined]
    sorting2 ["b", undefined, "a", null, "", undefined]

It looks like it didn't sort it at all, I would have expected something like: "a", "b", "", null, undefined, undefined.

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