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

Solution/RenatoMonroy #22

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

rdev32
Copy link

@rdev32 rdev32 commented Apr 21, 2023

Completed the challenge with all extra steps

@rdev32 rdev32 changed the title Challenge submit Renato Monroy Solution/renatomonroy Apr 21, 2023
@rdev32 rdev32 marked this pull request as draft April 21, 2023 17:59
@rdev32 rdev32 changed the title Solution/renatomonroy Solution/RenatoMonroy Apr 22, 2023
@rdev32 rdev32 marked this pull request as ready for review April 22, 2023 18:37

// iterate the names array and validate them with the method
console.log('Success');
for (const name of names) {
Copy link

Choose a reason for hiding this comment

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

just to add readability, always separate blocks of code like loops, conditionals, etc using a line break at the start of that block

Comment on lines +51 to +59
function callback(...params) {
if (params.length > 1)
console.log(`\nid: ${params[1].id}\nname: ${params[1].name}\n`);
else {
setTimeout(() => {
console.log(params[0].message);
}, 400);
}
}
Copy link

Choose a reason for hiding this comment

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

we must keep the standards, if we know that the first argument is the error, and the second argument is the data, we must name these parameters in this way, so it will help other devs to understand your code easily

Comment on lines +55 to +61
validateAsync(name, (...params) => {
if (params.length > 1) console.log(`\nid: ${params[1].id}\nname: ${params[1].name}\n`)
else throw new Error(params[0].message);
}).catch(error => setTimeout(() => console.error(error.message), 350));
}
setTimeout(() => console.log('Failure\n'), 350);
}
Copy link

Choose a reason for hiding this comment

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

since we've promised the validateName function, we could use promises or async/await on the validateAsync instead of a callback

Comment on lines +38 to +42
process.stdout.write(`${lname}, `);

// Firstname callback
firstnames(lname).then(fname => {
process.stdout.write(`${fname}\n`);
Copy link

Choose a reason for hiding this comment

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

since we are returning both lname and name together, we could just use a process.stdout.write in the second then method

function randomId() {
const desire = [1, -1];
const choice = Math.floor(Math.random() * desire.length);
return (Math.floor(Math.random() * 2)) ?
Copy link

Choose a reason for hiding this comment

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

the same recommendation about readability for a return

console.log({ id, product: promisesFulfilled[1], price: promisesFulfilled[0] });

} catch (error) {
/* NOTE : I've been trying to do proper error handling with all the promises but I had one struggle
Copy link

Choose a reason for hiding this comment

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

Keep in mind the difference between Promise.all and Promise.allSettled is that in the first an error could be thrown any moment so we should use a try/catch. But in the second case, it stores the results on each promise, so the error is stored too. It seems to me that line 64 is enough

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