I am not a JS/TS Guru, so i wanted to ask if one could write this better.
I needed a very primitive Full-Text-Search of some properties of an Object. What do you think?
export const search = <T, K extends keyof T>(term: string, objects: T[], keys: K[]): T[] => {
const foundObjects = objects.filter(x => {
for (const key of keys) {
if (x.hasOwnProperty(key) === false) {
continue;
}
const val = x[key];
if (typeof val === 'string' && val.toLowerCase().includes(term)) {
return true;
} else {
continue;
}
}
return false;
});
return foundObjects;
};