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

Konjit-w1-UsingAPIs #52

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

Conversation

konjit
Copy link

@konjit konjit commented Jan 28, 2025

Completed assignment for Week 1 of UsingAPIs.

@konjit konjit changed the title Solutions for Using APIs assignment week1 Konjit-w1-UsingAPIs Jan 28, 2025
Made the `is2Digit` function more readable.
@ddoyediran ddoyediran self-requested a review February 1, 2025 19:36
@ddoyediran ddoyediran self-assigned this Feb 1, 2025
export const getAnonName = (firstName) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (!firstName) {

Choose a reason for hiding this comment

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

Nice solution. I love that you handle the rejection (fail-first) first.

}

const is2Digit = (num) => num >= 10 && num <= 99;

Choose a reason for hiding this comment

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

Nice that you try to separate this into a function. Well done

.catch((error) => {
console.log(error.message);
})
.finally(() => {

Choose a reason for hiding this comment

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

Great job adding .finally() to ensure cleanup (logging "Roll finished") is executed regardless of whether the Promise resolves or rejects.

const dice = [1, 2, 3, 4, 5];
return rollDie(1);
const dicePromises = dice.map(() => rollDie());
return Promise.all(dicePromises);

Choose a reason for hiding this comment

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

Great Job

@@ -17,12 +17,23 @@ import { rollDie } from '../../helpers/pokerDiceRoller.js';
export function rollDice() {
const results = [];

// TODO: expand the chain to include five dice
return rollDie(1)
.then((value) => {

Choose a reason for hiding this comment

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

Great job, this works as expected.

But if you noticed, we are repeating these two codes from line 22 to 39:

 results.push(value);
 return rollDie(4);

We can prevent this with a Software engineering principle called "DRY Principle" by putting both as a function and use the function when needed. "Don't Repeat Yourself" (DRY) is a software development principle that helps us to avoid duplicating code. If you aren't aware of it, you can Google Search.


### 3-UsingAPIs - Week1

| Exercise | Passed | Failed | ESLint |

Choose a reason for hiding this comment

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

@konjit Great job completing week 1 assignment. Kudos!!! I will Approve it now.

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

Successfully merging this pull request may close these issues.

2 participants