Skip to content

Sorting of empty strings / null value is wrong #1

@vladshcherbin

Description

@vladshcherbin

Code:

const sort = require('deep-sort');

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

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

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

Output:

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

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

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.

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