File tree
Expand file treeCollapse file tree1 file changed
+12
-11
lines changed Expand file treeCollapse file tree1 file changed
+12
-11
lines changed Original file line number | Diff line number | Diff line change |
---|
|
1 |
| -export default async function asyncMapStrict(arr, fn) { |
2 |
| -const result = []; |
3 |
| - |
4 |
| -for (let idx = 0; idx < arr.length; idx += 1) { |
5 |
| -const cur = arr[idx]; |
6 |
| - |
7 |
| -// eslint-disable-next-line no-await-in-loop |
8 |
| -result.push(await fn(cur, idx, arr)); |
9 |
| -} |
10 |
| - |
11 |
| -return result; |
| 1 | +export default function asyncMapStrict(arr, fn) { |
| 2 | +return new Promise((resolve) => { |
| 3 | +const result = []; |
| 4 | +arr.reduce( |
| 5 | +(promise, cur, idx) => promise |
| 6 | +.then(() => fn(cur, idx, arr) |
| 7 | +.then((res) => { |
| 8 | +result.push(res); |
| 9 | +})), |
| 10 | +Promise.resolve(), |
| 11 | +).then(() => resolve(result)); |
| 12 | +}); |
12 | 13 | }
|
You can’t perform that action at this time.
0 commit comments