Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering on keys which hold the value of numerical zero gives inaccurate results #46

Closed
pushpinder107 opened this issue May 6, 2018 · 0 comments

Comments

@pushpinder107
Copy link
Contributor

  • match-sorter version: 2.2.1
  • node version: 8.9.4
  • npm (or yarn) version: 5.6.0

Relevant code or config

return value ? [].concat(value) : null

What you did:
Use data which contains the number 0 as a property value as below:

const objList = [
  {name: 'Janice', color: 'Green', rank:0},
  {name: 'Fred', color: 'Orange', rank:100},
  {name: 'George', color: 'Blue', rank:20},
  {name: 'Jen', color: 'Red', rank:0},
]

What happened:

The rows which have the numerical value zero are rejected falsely by the null check done while getting all items to compare.

Problem description:

matchSorter(objList, '0', {keys: ['name', 'rank']})

this returns:

[ {name: 'Fred', color: 'Orange', rank: 100 },
  { name: 'George', color: 'Blue', rank: 20 } ]

but should return:

[ {name: 'Janice', color: 'Green', rank:0},
{name: 'Jen', color: 'Red', rank:0}
{name: 'Fred', color: 'Orange', rank: 100 },
{name: 'George', color: 'Blue', rank: 20 } ]

Suggested solution:

Adding a check for the number zero in the return value of the function getItemValues.

return value || value === 0 ? [].concat(value) : null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants