filterBy not distinguish positive and negative number

Open Beginner friendly
#143 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
angular, javascript
Domain
frontend

Research direction

The issue is in the filterBy function of angular-filter. Look at the source code for the filterBy implementation, likely in a file like angular-filter.js or a specific filter module. The bug is that numeric comparison treats 1 and -1 as equal. Examine the comparison logic, likely using loose equality or absolute value. Write a test to reproduce the issue with an array [1, -1, 3, 5] and filter value 1, expecting only [1]. Modify the comparison to distinguish positive and negative numbers. Check existing tests for filterBy to ensure changes don't break other functionality.

Written by the indexing model from the issue text.

Description

Considering this code

block in orderjson.Blocks | filterBy: ['ID_Block']: block_NM.ID_Block

if ID_Block have on array values [1, -1,3,5] and filter is set to 1.
I expect to print just first value, but filter print also -1 because comparision consider 1,-1 the same.

On the flipside of the coin, using only positive values it works fine (no duplicates).

Dominant language
JavaScript
Stars
2.9k
Forks
319
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from a8m/angular-filter

All issues in a8m/angular-filter

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.