Bassam___JS2_Week2_HomeWork.#228
Bassam___JS2_Week2_HomeWork.#228BassamHager wants to merge 2 commits intoHackYourFuture:masterfrom BassamHager:week2
Conversation
yash-kapila
left a comment
There was a problem hiding this comment.
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. 🙂
| .map(rate => rate * hourlyRate) | ||
| .reduce((acc, curVal) => Math.round((acc + curVal) * 100) / 100); | ||
| return totalEarnings; | ||
| } |
There was a problem hiding this comment.
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.
| 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.
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,,,