Last active
August 9, 2023 14:18
-
-
Save ntnbst/2aebdc4fc8366465f8087286e369f58a 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
function myForEach<T>(arr: T[], forEachFunc: (v: T) => void) { | |
arr.reduce((acc, val) => { | |
forEachFunc(val) | |
return undefined; | |
}, undefined) | |
} | |
function myFilter<T> (arr: T[], filterFunc: (v: T) => boolean): T[] { | |
return arr.reduce((acc: T[], val) => { | |
if (filterFunc(val)) { | |
return [...acc, val] | |
} else { | |
return [...acc] | |
} | |
}, []) | |
} | |
function myMap<T, K>(arr: T[], mapFunc: (v: T) => K) { | |
return arr.reduce((acc: K[], curr) => [...acc, mapFunc(curr)], []) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment