Last active
April 15, 2025 14:11
-
-
Save andremury/47bc1ca00ca3dba2a1be3066095abcc5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 filterMap = <T = unknown, U = unknown>( | |
| arr: U[], | |
| condition: (item: U, index: number) => boolean, | |
| mapTo: (item: U, index: number) => T, | |
| ): T[] => { | |
| const newArray: T[] = []; | |
| for (let i = 0; i < arr.length; i++) { | |
| const item = arr[i]; | |
| if (condition(item, i)) { | |
| newArray.push(mapTo(item, i)); | |
| } | |
| } | |
| return newArray; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment