File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change 1- export default async function asyncReduce ( arr , fn , initialValue ) {
2- let temp = initialValue ;
3-
4- for ( let idx = 0 ; idx < arr . length ; idx += 1 ) {
5- const cur = arr [ idx ] ;
1+ import asyncForEachStrict from './forEach_strict' ;
62
7- // eslint-disable-next-line no-await-in-loop
8- temp = await fn ( temp , cur , idx ) ;
9- }
3+ export default function asyncReduce ( arr , fn , initialValue ) {
4+ let temp = initialValue ;
105
11- return temp ;
6+ return new Promise ( ( resolve ) => {
7+ // eslint-disable-next-line no-shadow
8+ asyncForEachStrict ( arr , ( cur , idx ) => new Promise ( ( resolve2 ) => {
9+ // eslint-disable-next-line no-await-in-loop
10+ fn ( temp , cur , idx ) . then ( ( result ) => { temp = result ; resolve2 ( ) ; } ) ;
11+ } ) )
12+ . then ( ( ) => { resolve ( temp ) ; } ) ;
13+ } ) ;
1214}
You can’t perform that action at this time.
0 commit comments