Skip to content

Commit

Permalink
refactor: simplify boolean check
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinsiva committed Jan 30, 2024
1 parent 07f1f3f commit 3d7b0fe
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,10 @@ Array.prototype.asyncSome = async function <T>(
const asyncResults: Promise<boolean>[] = [];
for (const el of this) {
const result = predicate(el);
if (typeof result === "boolean") {
if (result) {
return true;
}
} else {
asyncResults.push(result);
}
}
for (const result of asyncResults) {
if (await result) {
return true;
}
if (result === true) return true;
if (result instanceof Promise) asyncResults.push(result.then((r) => r || Promise.reject()));
}
return false;
return await Promise.any(asyncResults).catch(() => false);
};

Array.prototype.asyncMap = async function <T, V>(
Expand Down

0 comments on commit 3d7b0fe

Please sign in to comment.