Skip to content

Commit 5344a62

Browse files
authored
Update maartjes-work.js
1 parent 768acf2 commit 5344a62

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

Week2/homework/maartjes-work.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,43 @@ const maartjesTasks = monday.concat(tuesday);
4646
const maartjesHourlyRate = 20;
4747

4848
function computeEarnings(tasks, hourlyRate) {
49-
// Replace this comment and the next line with your code
50-
console.log(tasks, hourlyRate);
49+
//Map the tasks to durations in hours.
50+
const tasksDurationInHours = tasks.map(task => {
51+
return {
52+
name: task.name,
53+
duration: task.duration / 60,
54+
};
55+
});
56+
57+
58+
//Filter out everything that took less than two hours (i.e., remove from the collection)
59+
const filteredTask = tasksDurationInHours.filter(task => {
60+
if (task.duration < 2) {
61+
return false;
62+
} else {
63+
return true;
64+
}
65+
});
66+
67+
//Multiply the each duration by a per-hour rate for billing (use €20/hour) and sum it all up.
68+
const priceArray = filteredTask.map(task => task.duration * 20);
69+
70+
const totalPrice = priceArray.reduce((a, b) => a + b, 0);
71+
72+
return Math.round(totalPrice * 100) / 100;
5173
}
5274

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

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

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

6082
// Do not change or remove anything below this line
6183
module.exports = {
6284
maartjesTasks,
6385
maartjesHourlyRate,
6486
computeEarnings,
6587
};
88+

0 commit comments

Comments
 (0)