Skip to content

Instantly share code, notes, and snippets.

View kraizt's full-sized avatar
:octocat:
keep calm, keep learning.

Adimas Lutfi kraizt

:octocat:
keep calm, keep learning.
  • Yogyakarta
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