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

APIs week1 #4

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions 3-UsingAPIs/Week1/homework/ex4-pokerDiceAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ Can you explain why? Please add your answer as a comment to the end of the exerc
const rollDice = require('../../helpers/pokerDiceRoller');

function rollTheDices() {
// TODO Refactor this function
const dices = [1, 2, 3, 4, 5];
const resultPromises = [];
dices.forEach((dice) => {
resultPromises.push(rollDice(dice));
});
return resultPromises;
const resultPromises = dices.map((dice) => rollDice(dice));
return Promise.all(resultPromises);
}

Promise.all(rollTheDices())
rollTheDices()
.then((results) => console.log('Resolved!', results))
.catch((error) => console.log('Rejected!', error.message));

Choose a reason for hiding this comment

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

Yes!

Expand Down
5 changes: 5 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ ex3-rollDice.js
2021-03-22 02:12:27 info: ---------------------------------------------
2021-03-22 02:12:27 warn: A unit test file was not provided.
2021-03-22 02:12:46 info: All steps were completed successfully
2021-03-25 04:14:43 info: --------------------------------------------
2021-03-25 04:14:43 info: >>> Running Unit Test `ex4-pokerDiceAll` <<<
2021-03-25 04:14:43 info: --------------------------------------------
2021-03-25 04:15:38 info: All unit tests passed.
2021-03-25 04:15:56 info: All steps were completed successfully