Skip to content

Instantly share code, notes, and snippets.

@oleersoy
Last active September 26, 2019 02:08
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 oleersoy/32379106bd0457ff77ab8954400470ab to your computer and use it in GitHub Desktop.
Save oleersoy/32379106bd0457ff77ab8954400470ab to your computer and use it in GitHub Desktop.
const { isArray } = Array;
function search(entries: any[], search: string) {
search = search.toLowerCase();
return entries.filter(function (obj) {
const keys: string[] = Object.keys(obj);
return keys.some(function (key) {
const value = obj[key];
if (isArray(value)) {
return value.some(v => {
return v.toLowerCase().includes(search);
});
}
else if (!isArray(value)) {
return value.toLowerCase().includes(search);
}
})
});
}
let filtering = search(posts, 'filtering');
console.log("THE SEARCH RESULT IS: ", filtering);
let javascript = search(posts, 'javascript');
console.log("THE SEARCH RESULT IS: ", javascript);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment