@@ -23,31 +23,26 @@ _Deadline Wednesday_
23
23
24
24
1 . Say you would like to write a program that doubles the odd numbers in an array and throws away the even number.
25
25
26
- Your solution could be something like this:
27
- ``` js
28
- let numbers = [1 , 2 , 3 , 4 ];
29
- let newNumbers = [];
30
-
31
- for (let i = 0 ; i < numbers .length ; i++ ) {
32
- if (numbers[i] % 2 !== 0 ) {
33
- newNumbers[i] = numbers[i] * 2 ;
26
+ Your solution could be something like this:
27
+ ``` js
28
+ let numbers = [1 , 2 , 3 , 4 ];
29
+ let newNumbers = [];
30
+
31
+ for (let i = 0 ; i < numbers .length ; i++ ) {
32
+ if (numbers[i] % 2 !== 0 ) {
33
+ newNumbers .push (numbers[i] * 2 );
34
+ }
34
35
}
35
- }
36
36
37
- console .log (" The doubled numbers are" , newNumbers); // [2, 6]
37
+ console .log (" The doubled numbers are" , newNumbers); // [2, 6]
38
38
39
- ```
39
+ ```
40
40
41
- rewrite the above program using ` map ` and ` filter ` don't forget to use ` => `
41
+ Rewrite the above program using ` map` and ` filter` don' t forget to use `=>`
42
42
43
- 2 . Use the array of the previous assignment, write a program that add the even numbers to the resulting array twice, but the odd numbers only once. Don't forget to use ` => ` .
44
-
45
- Your output should be:
46
- ``` js
47
- console .log (" The final numbers are" , newNumbers);// [1, 2, 2, 3, 4, 4]
48
- ```
49
43
50
44
Underneath you see a very interesting small insight in Maartje' s work:
45
+
51
46
` ` ` js
52
47
let monday = [
53
48
{
@@ -67,10 +62,10 @@ let monday = [
67
62
duration : 200
68
63
}
69
64
];
70
-
65
+
71
66
let tuesday = [
72
67
{
73
- name : ' Keep writing summery ' ,
68
+ name : 'Keep writing summary ',
74
69
duration : 240
75
70
},
76
71
{
@@ -90,17 +85,16 @@ let tuesday = [
90
85
duration : 40
91
86
}
92
87
];
93
-
94
- let tasks = [ monday, tuesday] ;
88
+
89
+ let tasks = monday.concat( tuesday) ;
95
90
` ` `
96
91
97
- 3 . Write a program that does the following:
92
+ 2 . Write a program that does the following below . Use ` map ` and ` filter ` . You will also need a ` forEach ` or a ` for ` loop for the ' summing up ' part.
98
93
99
94
- Collect two days' worth of tasks.
100
95
- Convert the task durations to hours, instead of minutes.
101
- - Filter out everything that took two hours or more.
102
- - Sum it all up.
103
- - Multiply the result by a per-hour rate for billing (you can decide yourself what Maartje should make per hour).
96
+ - Filter out everything that took two hours or more
97
+ - Multiply the each duration by a per-hour rate for billing (you can decide yourself what Maartje should make per hour) and sum it all up.
104
98
- Output a formatted Euro amount.
105
99
- Don' t forget to use ` =>`
106
100
@@ -124,11 +118,57 @@ Go trough the reading material in the [README.md](/Week5/README.md) to prepare f
124
118
` ` `
125
119
How to hand in your homework:
126
120
• Clone your existing "hyf-javascript2" Github repository.
127
- • Create a new folder "week2" USING THE COMMAND LINE
128
- • Save your homework files inside this folder.
129
- • When you are done with your homework use add/commit and push to upload your homework.
121
+ • Create a new folder "week2" USING THE COMMAND LINE
122
+ • Save your homework files inside this folder.
123
+ • When you are done with your homework use add/commit and push to upload your homework.
130
124
• Write a description for your “commit”.
131
125
• Your hyf-javascript2/week2 should now contain all your homework files.
132
126
Place the link to your repository folder in Trello.
133
127
` ` `
134
128
129
+ <!--
130
+ let wage = tasks
131
+ .map ((task ) => {
132
+ return {
133
+ name: task .name ,
134
+ duration: task .duration / 60
135
+ }
136
+ })
137
+ .filter ((task ) => task .duration >= 2 )
138
+ .reduce ((wage , task ) => {
139
+ return wage + task .duration * 50
140
+ }, 0 );
141
+
142
+ console .log (` Maartje has earned € ${ wage .toFixed (2 )} ` );
143
+
144
+ let wage2 = 0 ;
145
+ tasks
146
+ .map ((task ) => {
147
+ return {
148
+ name: task .name ,
149
+ duration: task .duration / 60
150
+ }
151
+ })
152
+ .filter ((task ) => task .duration >= 2 )
153
+ .forEach ((task ) => {
154
+ wage2 += task .duration * 50
155
+ }, 0 );
156
+
157
+ console .log (` Maartje has earned € ${ wage2 .toFixed (2 )} ` );
158
+
159
+ let longTasks = tasks
160
+ .map ((task ) => {
161
+ return {
162
+ name: task .name ,
163
+ duration: task .duration / 60
164
+ }
165
+ })
166
+ .filter ((task ) => task .duration >= 2 );
167
+
168
+ let wage3 = 0 ;
169
+ for (let task of longTasks) {
170
+ wage3 += task .duration * 50
171
+ }
172
+
173
+ console .log (` Maartje has earned € ${ wage3 .toFixed (2 )} ` );
174
+ -->
0 commit comments