-
Notifications
You must be signed in to change notification settings - Fork 7
submit week3 assignment #14
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
base: main
Are you sure you want to change the base?
submit week3 assignment #14
Conversation
dardecena
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great effort...almost there. Please try exercise 3 and 5-q4 again.
I added some additional comments. Please reflect on them and keep them in mind for future assignments.
| function doubleEvenNumbers(numbers) { | ||
| // TODO rewrite the function body using `map` and `filter`. | ||
| return numbers.filter(n => n % 2 === 0).map(n => n * 2); | ||
| } | ||
| module.exports = doubleEvenNumbers; | ||
| // ! Unit test (using Jest) | ||
| describe('js-wk3-ex1-doubleEvenNumbers', () => { | ||
| test('doubleEvenNumbers should take the even numbers and double them', () => { | ||
| const actual = doubleEvenNumbers([1, 2, 3, 4]); | ||
| const expected = [4, 8]; | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a duplicate file. In the future, please edit assignment and remove redundant code/files before submitting.
| } | ||
| } | ||
| return newNumbers; | ||
| return numbers.filter(n => n % 2 === 0).map(n => n * 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job using the filter() and map() method 😄
| const eurosFormatter = new Intl.NumberFormat('nl-NL', { | ||
| style: 'currency', | ||
| currency: 'EUR', | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This returns a slightly different format than the expected value on the unit test (eg. '€NBSP187,50')
| function computeEarnings(tasks, hourlyRate) { | ||
| const totalMinutes = Array.isArray(tasks) | ||
| ? tasks.reduce((sum, t) => sum + (Number(t?.duration) || 0), 0) | ||
| : 0; | ||
|
|
||
| const totalHours = totalMinutes / 60; | ||
| const earnings = totalHours * Number(hourlyRate || 0); | ||
|
|
||
| return eurosFormatter.format(earnings); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job using the reduce() method.
Challenge: How would you rewrite this function if you were to also apply the map() function, and return the required format without using the eurosFormatter() function?
Note: The tests were removed from the file. Please restore them.
| @@ -0,0 +1,36 @@ | |||
| const sanitizeFruitBasket = require('./ex3-lemonAllergy'); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function sanitizeFruitBasket() seems to be incomplete. Could you try again?
| // prettier-ignore | ||
| // eslint-disable-next-line no-unused-vars | ||
| const quiz = { | ||
| q1: { answer: 'b' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| // eslint-disable-next-line no-unused-vars | ||
| const quiz = { | ||
| q1: { answer: 'b' }, | ||
| q2: { answer: 'c' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| const quiz = { | ||
| q1: { answer: 'b' }, | ||
| q2: { answer: 'c' }, | ||
| q3: { answer: 'a' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| q1: { answer: 'b' }, | ||
| q2: { answer: 'c' }, | ||
| q3: { answer: 'a' }, | ||
| q4: { answer: 'b' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Please try again.
| q2: { answer: 'c' }, | ||
| q3: { answer: 'a' }, | ||
| q4: { answer: 'b' }, | ||
| q5: { answer: 'c' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:+1
No description provided.