Skip to content

Commit c9cd92b

Browse files
committed
week2
1 parent bcf127e commit c9cd92b

3 files changed

Lines changed: 65 additions & 13 deletions

File tree

Week2/homework/maartjes_work.js

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,84 @@
1-
'use strict';
1+
"use strict";
22

3+
// 2.2
34
const monday = [
45
{
5-
name: 'Write a summary HTML/CSS',
6+
name: "Write a summary HTML/CSS",
67
duration: 180
78
},
89
{
9-
name: 'Some web development',
10+
name: "Some web development",
1011
duration: 120
1112
},
1213
{
13-
name: 'Fix homework for class10',
14+
name: "Fix homework for class10",
1415
duration: 20
1516
},
1617
{
17-
name: 'Talk to a lot of people',
18+
name: "Talk to a lot of people",
1819
duration: 200
1920
}
2021
];
2122

2223
const tuesday = [
2324
{
24-
name: 'Keep writing summary',
25+
name: "Keep writing summary",
2526
duration: 240
2627
},
2728
{
28-
name: 'Some more web development',
29+
name: "Some more web development",
2930
duration: 180
3031
},
3132
{
32-
name: 'Staring out the window',
33+
name: "Staring out the window",
3334
duration: 10
3435
},
3536
{
36-
name: 'Talk to a lot of people',
37+
name: "Talk to a lot of people",
3738
duration: 200
3839
},
3940
{
40-
name: 'Look at application assignments new students',
41+
name: "Look at application assignments new students",
4142
duration: 40
4243
}
4344
];
4445

4546
const tasks = monday.concat(tuesday);
4647

47-
// Add your code here
48+
let durationOfTasks = tasks.map(Element => Element.duration);
49+
50+
console.log(durationOfTasks);
51+
52+
// Map the tasks to durations in hours.
53+
let durationInHours = durationOfTasks
54+
.map(element => element / 60)
55+
56+
console.log(durationInHours);
57+
58+
// Filter out everything that took less than two hours
59+
60+
let lessThanTwoHours = durationInHours
61+
62+
.filter(element => element >= 2)
63+
console.log(lessThanTwoHours);
64+
65+
// Multiply the each duration by a per-hour rate for billing and sum it all up.
66+
67+
let paymentPerHour = durationOfTasks
68+
.map(element => (element / 60) * 100)
69+
70+
console.log(paymentPerHour);
71+
72+
let totalPayment = paymentPerHour
73+
.reduce(function (a, b) {
74+
return a + b;
75+
76+
});
77+
console.log(`Total hours payment is: ${totalPayment}`);
78+
79+
// Output a formatted Euro amount, rounded to Euro cents, e.g: € 12.34.
80+
81+
let amountEUR = totalPayment.toFixed(2);
82+
console.log(`The total amount to Euro is: ${amountEUR} EUR.`);
83+
84+

Week2/homework/map_filter.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
'use strict';
22

3-
const numbers = [1, 2, 3, 4];
3+
// 2.1
4+
let numbers = [1, 2, 3, 4, 5, 6];
45

5-
// Add your code here
6+
// const oddNumbers = numbers.filter(n => n % 2 !== 0);
7+
// const doubleOdds = oddNumbers.map(n => n * 2);
8+
9+
// console.log(`The odd numbers are: ${oddNumbers}, and doubled are: ${doubleOdds}.`);
10+
11+
// For cleaner code i can chaining this methods.
12+
13+
const items = numbers
14+
.filter(n => n % 2 !== 0)
15+
.map(n => n * 2);
16+
17+
console.log(items);

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)