Skip to content

Commit d5df280

Browse files
committed
Refactor someStrict to use asyncForEachStrict
1 parent 1238557 commit d5df280

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/some_strict.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
export default async function asyncSomeStrict(arr, fn) {
2-
for (let idx = 0; idx < arr.length; idx += 1) {
3-
const cur = arr[idx];
1+
import asyncForEachStrict from './forEach_strict';
42

5-
// eslint-disable-next-line no-await-in-loop
6-
const result = await fn(cur, idx, arr);
3+
export default function asyncSomeStrict(arr, fn) {
4+
return new Promise((resolve) => {
5+
// eslint-disable-next-line no-shadow
6+
asyncForEachStrict(arr, async (cur, idx, arr) => {
7+
const result = await fn(cur, idx, arr);
78

8-
if (result) {
9-
return true;
10-
}
11-
}
12-
13-
return false;
9+
if (result) {
10+
resolve(true);
11+
}
12+
}).then(() => {
13+
resolve(false);
14+
});
15+
});
1416
}

0 commit comments

Comments
 (0)