diff --git a/src/every.js b/src/every.js index 2ae40f6..7bb1587 100644 --- a/src/every.js +++ b/src/every.js @@ -3,14 +3,14 @@ import asyncForEach from './forEach'; export default function asyncSome(arr, fn) { return new Promise((resolve) => { // eslint-disable-next-line no-shadow - asyncForEach(arr, async (cur, idx, arr) => { - const result = await fn(cur, idx, arr); - - if (!result) { - resolve(false); - } - }).then(() => { - resolve(true); - }); + asyncForEach(arr, (cur, idx, arr) => new Promise((resolve2) => { + fn(cur, idx, arr).then((result) => { + if (!result) { + resolve(false); + } + resolve2(); + }); + })) + .then(() => { resolve(true); }); }); } diff --git a/src/every_strict.js b/src/every_strict.js index 2ac0193..595dace 100644 --- a/src/every_strict.js +++ b/src/every_strict.js @@ -3,14 +3,14 @@ import asyncForEachStrict from './forEach_strict'; export default function asyncEveryStrict(arr, fn) { return new Promise((resolve) => { // eslint-disable-next-line no-shadow - asyncForEachStrict(arr, async (cur, idx, arr) => { - const result = await fn(cur, idx, arr); - - if (!result) { - resolve(false); - } - }).then(() => { - resolve(true); - }); + asyncForEachStrict(arr, (cur, idx, arr) => new Promise((resolve2) => { + fn(cur, idx, arr).then((result) => { + if (!result) { + resolve(false); + } + resolve2(); + }); + })) + .then(() => { resolve(true); }); }); } diff --git a/src/filter.js b/src/filter.js index 3887351..a1adf71 100644 --- a/src/filter.js +++ b/src/filter.js @@ -4,12 +4,13 @@ export default function asyncSome(arr, fn) { const result = []; // eslint-disable-next-line no-shadow - return asyncForEach(arr, async (cur, idx, arr) => { - const cond = await fn(cur, idx, arr); - - if (cond) { - result[idx] = cur; - } - }) + return asyncForEach(arr, (cur, idx, arr) => new Promise((resolve) => { + fn(cur, idx, arr).then((cond) => { + if (cond) { + result[idx] = cur; + } + resolve(); + }); + })) .then(() => result.filter((cur, idx) => idx in result)); } diff --git a/src/filter_strict.js b/src/filter_strict.js index ee4e639..6a0779f 100644 --- a/src/filter_strict.js +++ b/src/filter_strict.js @@ -4,12 +4,13 @@ export default function asyncFilterStrict(arr, fn) { const result = []; // eslint-disable-next-line no-shadow - return asyncForEachStrict(arr, async (cur, idx, arr) => { - const cond = await fn(cur, idx, arr); - - if (cond) { - result[idx] = cur; - } - }) + return asyncForEachStrict(arr, (cur, idx, arr) => new Promise((resolve) => { + fn(cur, idx, arr).then((cond) => { + if (cond) { + result[idx] = cur; + } + resolve(); + }); + })) .then(() => result.filter((cur, idx) => idx in result)); } diff --git a/src/some.js b/src/some.js index 064c598..b35af20 100644 --- a/src/some.js +++ b/src/some.js @@ -3,14 +3,14 @@ import asyncForEach from './forEach'; export default function asyncSome(arr, fn) { return new Promise((resolve) => { // eslint-disable-next-line no-shadow - asyncForEach(arr, async (cur, idx, arr) => { - const result = await fn(cur, idx, arr); - - if (result) { - resolve(true); - } - }).then(() => { - resolve(false); - }); + asyncForEach(arr, (cur, idx, arr) => new Promise((resolve2) => { + fn(cur, idx, arr).then((result) => { + if (result) { + resolve(true); + } + resolve2(); + }); + })) + .then(() => { resolve(false); }); }); } diff --git a/src/some_strict.js b/src/some_strict.js index c0f0f9a..bb81fe3 100644 --- a/src/some_strict.js +++ b/src/some_strict.js @@ -3,14 +3,14 @@ import asyncForEachStrict from './forEach_strict'; export default function asyncSomeStrict(arr, fn) { return new Promise((resolve) => { // eslint-disable-next-line no-shadow - asyncForEachStrict(arr, async (cur, idx, arr) => { - const result = await fn(cur, idx, arr); - - if (result) { - resolve(true); - } - }).then(() => { - resolve(false); - }); + asyncForEachStrict(arr, (cur, idx, arr) => new Promise((resolve2) => { + fn(cur, idx, arr).then((result) => { + if (result) { + resolve(true); + } + resolve2(); + }); + })) + .then(() => { resolve(false); }); }); }