Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 817 Bytes

filterBy.md

File metadata and controls

27 lines (20 loc) · 817 Bytes

filterBy (source code)

  • Curried: true
  • Failsafe status: alternative available

The filterBy function filters an array of items based on pattern matching.

Arguments:

  • pattern: The pattern using which objects will be matched.
  • entityArray: The array of objects from which the objects with the given pattern will be returned.

Usage:

const array = [
  { name: "Oliver", age: 20 },
  { name: "Sam", age: 40 },
  { name: "George", age: 41 },
  { name: "Smith", age: 20 },
];

filterBy({ age: 20 }, array); // [{ name: "Oliver", age: 20 }, { name: "Smith", age: 20 }]
filterBy({ age: gt(__, 40) }, array); // [{ name: "George", age: 41 }]
filterBy({ age: 50 }, array); // []