Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

otus-learning
Copy link
Owner

No description provided.

@github-actions
Copy link

You can check this code at CodeSandbox with the link
https://githubbox.com/otus-learning/JS-Proffessional-03-2023/tree/hwForLection3

@@ -0,0 +1,26 @@
const fn1 = () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

где же типизация?

return memo * value;
}

function promiseReduce(asyncFunctions, reduce, initialValue) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

попробуй пробежаться по asyncFunctions через reduce, и код станет в разы чище

@@ -0,0 +1,40 @@
type PromiseFunc = () => Promise;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ну это не то, Promise принимает в себя дженерик. Сужай тип


export function promiseReduce(asyncFunctions : Array<PromiseFunc>, reduce : OurReduceFunc, initialValue : number) : Promise<number> {
return (asyncFunctions.length) ? asyncFunctions.reduce((prev, curr) =>
prev.then(memo => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай сделаем проще и сделаем через await механизм

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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

задачи возвращать промис не было. Зачем тебе делать await prev? ты возвращаешь промис, а потом его опять дожидаешься. Давай переделаем.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants