Last active
September 26, 2019 02:08
-
-
Save oleersoy/32379106bd0457ff77ab8954400470ab to your computer and use it in GitHub Desktop.
This file contains 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
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