@@ -23,31 +23,26 @@ _Deadline Wednesday_
2323
24241 . Say you would like to write a program that doubles the odd numbers in an array and throws away the even number.
2525
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+ }
3435 }
35- }
3636
37- console .log (" The doubled numbers are" , newNumbers); // [2, 6]
37+ console .log (" The doubled numbers are" , newNumbers); // [2, 6]
3838
39- ```
39+ ```
4040
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 `=>`
4242
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- ```
4943
5044Underneath you see a very interesting small insight in Maartje' s work:
45+
5146` ` ` js
5247let monday = [
5348 {
@@ -67,10 +62,10 @@ let monday = [
6762 duration : 200
6863 }
6964 ];
70-
65+
7166let tuesday = [
7267 {
73- name : ' Keep writing summery ' ,
68+ name : 'Keep writing summary ',
7469 duration : 240
7570 },
7671 {
@@ -90,17 +85,16 @@ let tuesday = [
9085 duration : 40
9186 }
9287 ];
93-
94- let tasks = [ monday, tuesday] ;
88+
89+ let tasks = monday.concat( tuesday) ;
9590` ` `
9691
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.
9893
9994- Collect two days' worth of tasks.
10095- 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.
10498- Output a formatted Euro amount.
10599- Don' t forget to use ` =>`
106100
@@ -124,11 +118,57 @@ Go trough the reading material in the [README.md](/Week5/README.md) to prepare f
124118` ` `
125119How to hand in your homework:
126120• 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.
130124• Write a description for your “commit”.
131125• Your hyf-javascript2/week2 should now contain all your homework files.
132126Place the link to your repository folder in Trello.
133127` ` `
134128
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