We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8ab8d3e commit f8914bfCopy full SHA for f8914bf
src/map_strict.js
@@ -1,12 +1,13 @@
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;
+export default function asyncMapStrict(arr, fn) {
+ return new Promise((resolve) => {
+ const result = [];
+ arr.reduce(
+ (promise, cur, idx) => promise
+ .then(() => fn(cur, idx, arr)
+ .then((res) => {
+ result.push(res);
+ })),
+ Promise.resolve(),
+ ).then(() => resolve(result));
12
+ });
13
}
0 commit comments