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

Implemented assignments #54

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

Conversation

samira313
Copy link

No description provided.

@samira313 samira313 force-pushed the Samira-w1-UsingAPIs branch from d856718 to 7a94968 Compare January 29, 2025 20:52
@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. Great approach handling the rejection (fail-first) first.

}
const is2Digit = (number) => {

Choose a reason for hiding this comment

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

Well done with your solution. It works but we can improve it bit.

Firstly, nice that we are using a function is2Digit to determine whether a given number is a two-digit number.
Our current function uses a while loop to repeatedly divide the number by 10 until it becomes 0. Using while loop here makes our solution a bit inefficient (time-wise). This iterative process is computationally expensive for larger numbers, even though the problem only requires checking for two digits.

Note: Two digit number is a number that is equal to or greater than 10 and also a number that is equal to or less than 99 (e.g 10, 11, 12, ..., 97, 98, 99). Therefore, we can use an if statement to check this.

Alternaive approach:

const is2Digit = (number) => {
  return number >= 10 && number <= 99;
};

In this solution, we are not checking edge cases such as when the number is a negative number.

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

Choose a reason for hiding this comment

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

Great job.

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

// TODO: expand the chain to include five dice
return rollDie(1)
.then((value) => {
results.push(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.

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

@samira313
Copy link
Author

samira313 commented Feb 3, 2025 via email

@ddoyediran
Copy link

You are welcome. I look forward to the changes.

@samira313
Copy link
Author

samira313 commented Feb 4, 2025 via email

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