Skip to content

Instantly share code, notes, and snippets.

@AlexeyPogorelov
Created February 17, 2021 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexeyPogorelov/4d0379680408eb7ad542b593f5f4a46f to your computer and use it in GitHub Desktop.
Save AlexeyPogorelov/4d0379680408eb7ad542b593f5f4a46f to your computer and use it in GitHub Desktop.
filter (or / and)
const getCheckFunction = (params, isAnd) => {
const action = isAnd ? "every" : "some";
const entries = Object.entries(params);
return (object) => {
return entries[action](([key, value]) => object[key] === value);
};
};
const filter = (array, params, isAnd) => {
return array.filter(getCheckFunction(params, isAnd));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment