-
Notifications
You must be signed in to change notification settings - Fork 328
Conversation
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.
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; | ||
} |
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.
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); |
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.
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);
Thanks & Regards,,,