Skip to content

Instantly share code, notes, and snippets.

@andremury
Created March 29, 2023 21:22
Show Gist options
  • Save andremury/47bc1ca00ca3dba2a1be3066095abcc5 to your computer and use it in GitHub Desktop.
Save andremury/47bc1ca00ca3dba2a1be3066095abcc5 to your computer and use it in GitHub Desktop.
export const mapFilter = <T = unknown, U = unknown>(
arr: U[],
condition: (item: U) => boolean,
mapTo: (item: U) => T
): T[] => {
const newArray: T[] = [];
for (const item of arr) {
if (condition(item)) {
newArray.push(mapTo(item));
}
}
return newArray;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment