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
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"prefer-arrow-callback": "off",
"prefer-destructuring": "off",
"prefer-template": "off",
"trailing-comma": "off"
"trailing-comma": "off",
"linebreak-style": "off"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ typings/

.netlify
dist/
live/
1 change: 0 additions & 1 deletion Week1/homework/style.css
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
/* add your styling here */
11 changes: 8 additions & 3 deletions Week2/homework/maartjes-work.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,21 @@ const maartjesTasks = monday.concat(tuesday);
const maartjesHourlyRate = 20;

function computeEarnings(tasks, hourlyRate) {
// Replace this comment and the next line with your code
console.log(tasks, hourlyRate);
const totalEarnings = tasks
.map(task => task.duration / 60)
.filter(hours => hours >= 2)
.map(hours => hours * 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.


// eslint-disable-next-line no-unused-vars
const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate);

// add code to convert `earnings` to a string rounded to two decimals (euro cents)

console.log(`Maartje has earned €${'replace this string with the earnings rounded to euro cents'}`);
// console.log(`Maartje has earned €${'replace this string with the earnings rounded to euro cents'}`);
console.log(`Maartje has earned € ${earnings}`);

// Do not change or remove anything below this line
module.exports = {
Expand Down
3 changes: 1 addition & 2 deletions Week2/homework/map-filter.js
Original file line number Diff line number Diff line change
@@ -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);

}

const myNumbers = [1, 2, 3, 4];
Expand Down