Use partition func instead + use Promise.all

This commit is contained in:
Madeline
2023-04-11 12:56:32 +10:00
parent 6a148898a5
commit debfaea866
3 changed files with 23 additions and 27 deletions
+8
View File
@@ -21,3 +21,11 @@
export function containsAll(arr: unknown[], target: unknown[]) {
return target.every((v) => arr.includes(v));
}
/* https://stackoverflow.com/a/50636286 */
export function partition<T>(array: T[], filter: (elem: T) => boolean) {
const pass: T[] = [],
fail: T[] = [];
array.forEach((e) => (filter(e) ? pass : fail).push(e));
return [pass, fail];
}