-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Homework for lection #3 first commit #2
base: main
Are you sure you want to change the base?
Conversation
You can check this code at CodeSandbox with the link |
src/promiseReducer.js
Outdated
@@ -0,0 +1,26 @@ | |||
const fn1 = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
где же типизация?
src/promiseReducer.js
Outdated
return memo * value; | ||
} | ||
|
||
function promiseReduce(asyncFunctions, reduce, initialValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
попробуй пробежаться по asyncFunctions через reduce, и код станет в разы чище
src/promiseReducer.ts
Outdated
@@ -0,0 +1,40 @@ | |||
type PromiseFunc = () => Promise; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ну это не то, Promise принимает в себя дженерик. Сужай тип
src/promiseReducer.ts
Outdated
|
||
export function promiseReduce(asyncFunctions : Array<PromiseFunc>, reduce : OurReduceFunc, initialValue : number) : Promise<number> { | ||
return (asyncFunctions.length) ? asyncFunctions.reduce((prev, curr) => | ||
prev.then(memo => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
давай сделаем проще и сделаем через await механизм
src/promiseReducer.ts
Outdated
return (asyncFunctions.length) ? asyncFunctions.reduce(async (prev : Promise<number>, curr : PromiseFunc) => { | ||
const memo = await prev; | ||
const data = await curr(); | ||
return Promise.resolve(reduce(memo, data)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
задачи возвращать промис не было. Зачем тебе делать await prev? ты возвращаешь промис, а потом его опять дожидаешься. Давай переделаем.
No description provided.