Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit baad154

Browse files
authored
Add files via upload
1 parent d558e4e commit baad154

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

Week2/homework/maartjes-work.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'use strict';
2+
3+
const monday = [{
4+
name: 'Write a summary HTML/CSS',
5+
duration: 180
6+
},
7+
{
8+
name: 'Some web development',
9+
duration: 120
10+
},
11+
{
12+
name: 'Fix homework for class10',
13+
duration: 20
14+
},
15+
{
16+
name: 'Talk to a lot of people',
17+
duration: 200
18+
}
19+
];
20+
21+
const tuesday = [{
22+
name: 'Keep writing summary',
23+
duration: 240
24+
},
25+
{
26+
name: 'Some more web development',
27+
duration: 180
28+
},
29+
{
30+
name: 'Staring out the window',
31+
duration: 10
32+
},
33+
{
34+
name: 'Talk to a lot of people',
35+
duration: 200
36+
},
37+
{
38+
name: 'Look at application assignments new students',
39+
duration: 40
40+
}
41+
];
42+
43+
const maartjesTasks = monday.concat(tuesday);
44+
const maartjesHourlyRate = 20;
45+
46+
// Map the tasks to durations in hours.
47+
const tasksInHour = maartjesTasks.map(tasks => tasks.duration / 60);
48+
49+
// Filter out everything that took less than two hours
50+
const longTasks = tasksInHour.filter(task => {
51+
return task >= 2;
52+
});
53+
54+
// Multiply the each duration by a per-hour rate for billing (use €20/hour) and sum it all up
55+
const profits = longTasks.map(task => {
56+
return task * 20;
57+
});
58+
59+
let totalProfit = 0;
60+
profits.forEach(function (profit) {
61+
totalProfit += profit;
62+
});
63+
64+
// Output a formatted Euro amount, rounded to Euro cents, e.g: €11.34
65+
const roundedTotalProfit = totalProfit.toFixed(2);
66+
67+
// add code to convert `earnings` to a string rounded to two decimals (euro cents)
68+
console.log(`Maartje has earned €${roundedTotalProfit}`);

Week2/homework/map-filter.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function doubleOddNumbers(numbers) {
2+
const newNumbers = [];
3+
for (let i = 0; i < numbers.length; i++) {
4+
if (numbers[i] % 2 !== 0) {
5+
newNumbers.push(numbers[i] * 2);
6+
}
7+
}
8+
return newNumbers;
9+
}
10+
11+
const myNumbers = [1, 2, 3, 4];
12+
console.log(doubleOddNumbers(myNumbers)); // ==> [2, 6]
13+
14+
// Rewrite the above doubleOddNumbers function using map and filter; don't forget to use =>
15+
const myOddNumbers = myNumbers.filter(myNumber => myNumber % 2 !== 0).map(myNumber => myNumber * 2);
16+
console.log(myOddNumbers);
17+
// Do not change or remove anything below this line
18+
module.exports = {
19+
myNumbers,
20+
doubleOddNumbers
21+
};

0 commit comments

Comments
 (0)