Created
October 9, 2023 20:41
-
-
Save olibooty/aae7ec0314d81dbd26a2bdf8dda8b047 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 filterByPropertyKey = <TObj extends Object,>( | |
| collection: Readonly<TObj[]>, | |
| filters: Record<string, unknown>, | |
| ) => { | |
| if (Object.keys(filters).length === 0) { | |
| return collection; | |
| } | |
| return collection.filter((item) => { | |
| let include = true; | |
| for (const key in item) { | |
| if (filters[key] === undefined) { | |
| continue; | |
| } | |
| include = include && item[key] === filters[key]; | |
| } | |
| return include; | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment