Skip to content

Instantly share code, notes, and snippets.

View ilyasahsan123's full-sized avatar

ilyas ahsan ilyasahsan123

  • Jakarta, Indonesia
  • 22:31 (UTC +07:00)
View GitHub Profile
@jherax
jherax / arrayFilterFactory.1.ts
Last active July 18, 2024 15:02
Filters an array of objects with multiple match-criteria.
type FilterOperator = 'AND' | 'OR';
type FiltersBy<T> = {
[K in keyof T]?: (value: T[K]) => boolean;
};
/**
* Factory function that creates a specialized function to filter
* arrays, by validating all filters (AND operator),
* or validating just one of the filters (OR operator).
* @param operator Method to validate all filters: AND, OR