Skip to content

VigneshMurugan/multi-array-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

multi-array-filter

Filter an Array using multiple predicates

It takes 2 mandatory arguments and 2 optional argument.

  • First parameter is the input array.
  • Second argument is array of predicates which needs to validated against the array.
  • Third argument is optional boolean which indicates whether an item should pass all predicates or atleast one predicate. true validates that all predicates are satisfied and false validates atleast one predicate is satisfied
  • Fourth Argument is optional comparator function to sort the resultant array
import filterArray from 'multi-filter-array'

const addressListArray = [{
    name: 'TestUser1',
    email: 'TestUser1@mail.com',
    age: 25,
    address: 'TestCountry1'
  },
  {
    name: 'TestUser2',
    email: 'TestUser2@mail.com',
    age: 35,
    address: 'TestCountry2'
  },
  {
    name: 'TestUser3',
    email: 'TestUser3@mail.com',
    age: 28,
    address: 'TestCountry1'
  }
];

filterArray(addressListArray, [person => person.address == 'TestCountry1', person => person.name == 'TestUser3'])

About

Filter an Array using multiple predicates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •