Skip to content

Instantly share code, notes, and snippets.

View renomureza's full-sized avatar

Renova M. R renomureza

View GitHub Profile
@vladilenm
vladilenm / Composition.js
Last active May 24, 2023 13:22
Inheritance vs Composition in JavaScript
function createProgrammer(name) {
const programmer = {name}
return {
...programmer,
...canCode(programmer)
}
}
function canCode({ name }) {
return {
@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