Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Bassam___JS2_Week2_HomeWork. #228

Closed
wants to merge 2 commits into from
Closed

Bassam___JS2_Week2_HomeWork. #228

wants to merge 2 commits into from

Conversation

BassamHager
Copy link

Thanks & Regards,,,

yash-kapila
yash-kapila previously approved these changes Jan 18, 2019
Copy link

@yash-kapila yash-kapila left a comment

Choose a reason for hiding this comment

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

Hi @BassamHajar - I've reviewed your assignment and it seems good to me. I liked how you used method chaining to finish 1.2. I've left a couple of comments for you to have a look. I think variable naming conventions is important so would like you to be mindful of it in the future. Approving your PR. πŸ™‚

.filter(rate => rate >= 2)
.map(rate => rate * hourlyRate)
.reduce((acc, curVal) => Math.round((acc + curVal) * 100) / 100);
return totalEarnings;
}

Choose a reason for hiding this comment

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

Hi @BassamHajar - I liked how you used method chaining here to accomplish the desired results. I would like to add one thing here though. Although it might seem a small thing but giving appropriate names to variables inside methods like map, filter and reduce is quite important. I see that you have done a mix of both.

For example, the map method uses task as an internal variable correctly. However, filter method uses rate as the variable name when hour might have been more appropriate because we are filtering out hours here. Similarly, inside reduce, you have used acc and curVal which might have been coming from the APIs of the reduce method but having total, amount would have been more appropriate. Don't you think? πŸ™‚

Please be mindful of variable naming conventions. Even though they are small things but they happen to make you lot better.

@@ -1,8 +1,7 @@
'use strict';

function doubleOddNumbers(numbers) {
// Replace this comment and the next line with your code
console.log(numbers);
return numbers.filter(num => num % 2 !== 0).map(num => num * 2);

Choose a reason for hiding this comment

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

Just FYI - you can also use arrow functions here to replace the function definition using function keyword with function expressions i.e

const doubleOddNumbers = numbers => numbers
  .filter(num => num % 2 !== 0)
  .map(num => num * 2);

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

Successfully merging this pull request may close these issues.

4 participants