add filterObjectsByStringEntries utility function

This commit is contained in:
marlon-erler
2024-07-24 17:37:18 +02:00
parent 6edb73caec
commit dd9090bc4e
2 changed files with 45 additions and 10 deletions
+15
View File
@@ -28,6 +28,21 @@ export class HandlerManager<T> {
};
}
// filters
export function filterObjectsByStringEntries(reference: {[key: string]: string}, objects: any[]): any[] {
const matches: any[] = [];
object_loop: for (const object of objects) {
reference_entry_loop: for (const referenceEntry of Object.entries(reference)) {
const [key, value] = referenceEntry;
if (object[key] != value) continue object_loop
}
matches.push(object);
}
return matches;
}
// sorting
export class IndexManager<T> {
private itemToString: (item: T) => string;