Skip to content

Empty strings and null values are at the beginning of the array #5

@vladshcherbin

Description

@vladshcherbin

Code:

const emptyStringTestArray = [
  { title: 'b' },
  { title: '' },
  { title: 'a' }
]

const nullTestArray = [
  { title: 'b' },
  { title: null },
  { title: 'a' }
]

console.log(emptyStringTestArray.sort(international('title')))
console.log(nullTestArray.sort(international('title')))

Output:

[
  { title: '' },
  { title: 'a' },
  { title: 'b' }
]

[
  { title: null },
  { title: 'a' },
  { title: 'b' }
]

Expected output:

[
  { title: 'a' },
  { title: 'b' },
  { title: '' }
]

[
  { title: 'a' },
  { title: 'b' },
  { title: null }
]

Since it's sorting by string alphabetically, I'd expect to see empty string or null values at the end of the array, not at the beginning.

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