Created
March 29, 2023 21:22
-
-
Save andremury/47bc1ca00ca3dba2a1be3066095abcc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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