From 1ac7f03abe03d11f1c68a719db6117e7d856edb0 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 11 Feb 2019 11:29:37 +0100 Subject: [PATCH 01/18] Update map-filter.js --- Week2/homework/map-filter.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Week2/homework/map-filter.js b/Week2/homework/map-filter.js index c8e8a88c1..861f10447 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -1,13 +1,20 @@ 'use strict'; - -function doubleOddNumbers(numbers) { - // Replace this comment and the next line with your code - console.log(numbers); +//1.1 Rewrite the above doubleOddNumbers function using map and filter; don't forget to use =>. +function doubleOddNumbers(myNumbers) { + let oddNumbers = []; + for (let i = 0; i < myNumbers.length; i++) { + if (myNumbers[i] % 2 !== 0) { + oddNumbers.push(myNumbers[i] * 2); + } + } + return oddNumbers; } - const myNumbers = [1, 2, 3, 4]; console.log(doubleOddNumbers(myNumbers)); +//Rewrite the above doubleOddNumbers function using map and filter; don't forget to use =>. +const myOddNumbers = myNumbers.filter(myNumber => myNumber % 2 !== 0).map(myNumber => myNumber * 2); +console.log(myOddNumbers); // Do not change or remove anything below this line module.exports = { myNumbers, From 584d2f023d289e01264dc5b470bca82e21415227 Mon Sep 17 00:00:00 2001 From: Ada Date: Thu, 14 Feb 2019 20:30:18 +0100 Subject: [PATCH 02/18] First Commit --- Week2/homework/maartjes-work.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 49772eb44..4e3e59944 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -45,6 +45,32 @@ const tuesday = [ const maartjesTasks = monday.concat(tuesday); const maartjesHourlyRate = 20; +const maartjesTasks = monday.concat(tuesday); +const maartjesHourlyRate = 20; +-------------------------------------------First Solustion------------------------------------------------------------------ +//Map the tasks to durations in hours. +let tasksInHour = maartjesTasks.map(tasks => tasks.duration / 60); + +//Filter out everything that took less than two hours +let longTasks = tasksInHour.filter(task => { + return task >= 2; +}); + +//Multiply the each duration by a per-hour rate for billing (use €20/hour) and sum it all up +let profits = longTasks.map(task => { + return task * 25; +}); + +let totalProfit = 0; +profits.forEach(function(profit) { + totalProfit += profit; +}); + +//Output a formatted Euro amount, rounded to Euro cents, e.g: €11.34 +let roundedTotalProfit = totalProfit.toFixed(2); + + +------------------------------------------Second Solution------------------------------------------------------------------- function computeEarnings(tasks, hourlyRate) { // Replace this comment and the next line with your code console.log(tasks, hourlyRate); From fadfb0b86a75941fb5037947e3a410621b39f2fe Mon Sep 17 00:00:00 2001 From: Ada Date: Thu, 14 Feb 2019 20:32:15 +0100 Subject: [PATCH 03/18] Update maartjes-work.js --- Week2/homework/maartjes-work.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 4e3e59944..204cd8d5e 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -45,8 +45,6 @@ const tuesday = [ const maartjesTasks = monday.concat(tuesday); const maartjesHourlyRate = 20; -const maartjesTasks = monday.concat(tuesday); -const maartjesHourlyRate = 20; -------------------------------------------First Solustion------------------------------------------------------------------ //Map the tasks to durations in hours. let tasksInHour = maartjesTasks.map(tasks => tasks.duration / 60); From cb4265a681b87c341123ca92d82e8914ca02f170 Mon Sep 17 00:00:00 2001 From: Ada Date: Thu, 14 Feb 2019 20:35:11 +0100 Subject: [PATCH 04/18] First Commit --- Week2/homework/maartjes-work.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 204cd8d5e..2d1b380bc 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -56,7 +56,7 @@ let longTasks = tasksInHour.filter(task => { //Multiply the each duration by a per-hour rate for billing (use €20/hour) and sum it all up let profits = longTasks.map(task => { - return task * 25; + return task * 20; }); let totalProfit = 0; From 570be6814d54763a934dc8edaa00b871bf9324a8 Mon Sep 17 00:00:00 2001 From: Ada Date: Thu, 14 Feb 2019 20:37:21 +0100 Subject: [PATCH 05/18] Update maartjes-work.js --- Week2/homework/maartjes-work.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 2d1b380bc..4da9c26c9 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -67,6 +67,9 @@ profits.forEach(function(profit) { //Output a formatted Euro amount, rounded to Euro cents, e.g: €11.34 let roundedTotalProfit = totalProfit.toFixed(2); +// add code to convert `earnings` to a string rounded to two decimals (euro cents) +console.log(`Maartje has earned €${roundedTotalProfit}`); + ------------------------------------------Second Solution------------------------------------------------------------------- function computeEarnings(tasks, hourlyRate) { From e3ebdea975ee12e172796e0f97b67d5c8b4e56a4 Mon Sep 17 00:00:00 2001 From: Ada Date: Thu, 14 Feb 2019 22:56:34 +0100 Subject: [PATCH 06/18] First Commit --- Week2/homework/maartjes-work.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 4da9c26c9..f85a399d4 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -73,16 +73,22 @@ console.log(`Maartje has earned €${roundedTotalProfit}`); ------------------------------------------Second Solution------------------------------------------------------------------- function computeEarnings(tasks, hourlyRate) { - // Replace this comment and the next line with your code - console.log(tasks, hourlyRate); -} + let profits = []; + tasks.forEach(function(task) { + let duration = task.duration / 60; + if (duration >= 2) { + profits.push(duration * hourlyRate); + } + }); + let totalProfits = profits.reduce((accumulator, currentValue) => accumulator + currentValue, 0); + return totalProfits; + } -// eslint-disable-next-line no-unused-vars -const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); + // eslint-disable-next-line no-unused-vars + const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate).toFixed(2); -// add code to convert `earnings` to a string rounded to two decimals (euro cents) - -console.log(`Maartje has earned €${'replace this string with the earnings rounded to euro cents'}`); + // add code to convert `earnings` to a string rounded to two decimals (euro cents) + console.log(`Maartje has earned €${earnings}`); // Do not change or remove anything below this line module.exports = { From 4af1060d01750c6b1b4ff97ae8e9f8bd3ed63460 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 15:48:54 +0100 Subject: [PATCH 07/18] First Commit For, while and do while loops --- Week3/homework/step2-3.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Week3/homework/step2-3.js b/Week3/homework/step2-3.js index 00845c5eb..0b5b39b6c 100644 --- a/Week3/homework/step2-3.js +++ b/Week3/homework/step2-3.js @@ -4,13 +4,14 @@ function repeatStringNumTimesWithFor(str, num) { // eslint-disable-next-line prefer-const let result = ''; - - // Replace this comment and the next line with your code - console.log(str, num, result); - + for (let i = 0; i < num; i++) { + result += str; + if (i === num) { + return result; + } + } return result; } - console.log('for', repeatStringNumTimesWithFor('abc', 3)); // Use a 'while' loop @@ -18,8 +19,10 @@ function repeatStringNumTimesWithWhile(str, num) { // eslint-disable-next-line prefer-const let result = ''; - // Replace this comment and the next line with your code - console.log(str, num, result); + while (num > 0) { + result += str; + num--; + } return result; } @@ -31,8 +34,10 @@ function repeatStringNumTimesWithDoWhile(str, num) { // eslint-disable-next-line prefer-const let result = ''; - // Replace this comment and the next line with your code - console.log(str, num, result); + do { + result += str; + num--; + } while (num > 0); return result; } From 4256a209ba2e0bf5159fad42882296441514aca0 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 16:42:39 +0100 Subject: [PATCH 08/18] First Commit threeFive solution --- Week3/homework/step2-2.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Week3/homework/step2-2.js b/Week3/homework/step2-2.js index dcd135040..f9c57fc8b 100644 --- a/Week3/homework/step2-2.js +++ b/Week3/homework/step2-2.js @@ -2,19 +2,25 @@ function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { const numbers = []; + for (let number = startIndex; number <= stopIndex; number++) { + numbers.push(number); + if (number % 3 === 0) { + sayThree(number); + } + if (number % 5 === 0) { + sayFive(number); + } + } - // Replace this comment and the next line with your code - console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers); + console.log(numbers); } function sayThree(number) { - // Replace this comment and the next line with your code - console.log(number); + console.log(sayThree); } function sayFive(number) { - // Replace this comment and the next line with your code - console.log(number); + console.log(sayFive); } threeFive(10, 15, sayThree, sayFive); From 3bb714f0c0174ca8ad2322b59660daae65e78746 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 16:49:46 +0100 Subject: [PATCH 09/18] First Commit Constructor Function --- Week3/homework/step2-4.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Week3/homework/step2-4.js b/Week3/homework/step2-4.js index b11b1dcb6..2dab07e87 100644 --- a/Week3/homework/step2-4.js +++ b/Week3/homework/step2-4.js @@ -1,10 +1,15 @@ 'use strict'; function Dog() { - // add your code here + this.name = 'Carry'; + this.color = 'black'; + this.numLegs = 4; } const hound = new Dog(); +hound.name = 'Isabella'; +hound.color = 'Gray'; +hound.numLegs = 4; // Do not change or remove anything below this line module.exports = hound; From 06a8abcaa8ef73ac2cf2d24be08095c45a117c54 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 16:57:36 +0100 Subject: [PATCH 10/18] First Commit Nested Loops --- Week3/homework/step2-5.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Week3/homework/step2-5.js b/Week3/homework/step2-5.js index cbb54fa1d..ff7d18590 100644 --- a/Week3/homework/step2-5.js +++ b/Week3/homework/step2-5.js @@ -3,9 +3,11 @@ function multiplyAll(arr) { // eslint-disable-next-line let product = 1; - - // Replace this comment and the next line with your code - console.log(arr, product); + for (let i = 0; i < arr.length; i++) { + for (let j = 0; j < arr[i].length; j++) { + product *= arr[i][j]; + } + } return product; } From 4981f18c301548e3100ee3eacf960d36fe6fa1ac Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 20:44:03 +0100 Subject: [PATCH 11/18] First Commit Loop inside arrays --- Week3/homework/step2-6.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Week3/homework/step2-6.js b/Week3/homework/step2-6.js index ffe95b9f7..dd7e501dd 100644 --- a/Week3/homework/step2-6.js +++ b/Week3/homework/step2-6.js @@ -3,14 +3,27 @@ const arr2d = [[1, 2], [3, 4], [5, 6]]; const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]; +let my2dArr = []; + function flattenArray2d(arr) { - // Replace this comment and the next line with your code - console.log(arr); + for (let i = 0; i < arr2d.length; i++) { + for (let j = 0; j < arr2d[i].length; j++) { + my2dArr.push(arr2d[i][j]); + } + } + return my2dArr; } +let my3dArr = []; function flattenArray3d(arr) { - // Replace this comment and the next line with your code - console.log(arr); + for (let i = 0; i < arr3d.length; i++) { + for (let j = 0; j < arr3d[i].length; j++) { + for (let k = 0; k < arr3d[j].length; k++) { + my3dArr.push(arr3d[i][j][k]); + } + } + } + return my3dArr; } console.log(flattenArray2d(arr2d)); // -> [1, 2, 3, 4, 5, 6] From 3282fe9382f9a7decea7892274331692b3d58b46 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 21:02:52 +0100 Subject: [PATCH 12/18] First Commit --- Week3/homework/step2-7.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Week3/homework/step2-7.js b/Week3/homework/step2-7.js index 3e72e8551..357e6cc64 100644 --- a/Week3/homework/step2-7.js +++ b/Week3/homework/step2-7.js @@ -21,3 +21,9 @@ f2(y); console.log(y); // Add your explanation as a comment here + +/* In the first function: +- The variable x is assign to 9, the function increment 9 to 10. But since x is a const variable when console.log calls for x, the function prints out the const variable value which is 9. + In the second function: +- variable y is an object, the function use the key x to change the value of 9. It increment it to 10 and assign it to x. when the console.log calls for y, variable y finds the x and the value 10 which is assigned to it. */ + From 8c0979c2bb865d1f28fd0c0e06b2e339f03ebdf9 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 21:22:57 +0100 Subject: [PATCH 13/18] First Commit --- Week3/homework/step3.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Week3/homework/step3.js b/Week3/homework/step3.js index 292724bf4..ec51793e8 100644 --- a/Week3/homework/step3.js +++ b/Week3/homework/step3.js @@ -1,8 +1,9 @@ 'use strict'; function createBase(base) { - // Replace this comment and the next line with your code - console.log(base); + return function(base) { + return base + 6; + }; } const addSix = createBase(6); From 6e101f4feb2f0a24bf9560e22167477cb1d12b1f Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 21:27:24 +0100 Subject: [PATCH 14/18] First Commit --- Week3/homework/step3-bonus.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Week3/homework/step3-bonus.js b/Week3/homework/step3-bonus.js index 917091d61..68492d4be 100644 --- a/Week3/homework/step3-bonus.js +++ b/Week3/homework/step3-bonus.js @@ -3,10 +3,16 @@ const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; function makeUnique(arr) { - // Replace this comment and the next line with your code - console.log(arr); +var myUniqueArray = []; + arr.forEach(function(element) { + if (myUniqueArray.indexOf(element) === -1) { + myUniqueArray.push(element); + } + }); + return myUniqueArray; } + const uniqueValues = makeUnique(values); console.log(uniqueValues); From 0572b80e94d66e284f4f49493a8f320fee3a5011 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 21:34:27 +0100 Subject: [PATCH 15/18] First Commit --- Week3/homework/step2-1.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Week3/homework/step2-1.js b/Week3/homework/step2-1.js index d5699882c..511052a76 100644 --- a/Week3/homework/step2-1.js +++ b/Week3/homework/step2-1.js @@ -1,9 +1,7 @@ 'use strict'; function foo(func) { - // What to do here? - // Replace this comment and the next line with your code - console.log(func); + bar(); } function bar() { From 8d94e0fbdeb9496949fac7cd85d6e0d846e8bd8d Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 22:04:43 +0100 Subject: [PATCH 16/18] First Commit --- Week3/homework/step2-1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week3/homework/step2-1.js b/Week3/homework/step2-1.js index 511052a76..28fa47a4b 100644 --- a/Week3/homework/step2-1.js +++ b/Week3/homework/step2-1.js @@ -1,7 +1,7 @@ 'use strict'; function foo(func) { - bar(); + func(); } function bar() { From 6f879fc365a8769619813a32d4bb071890871944 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 22:05:44 +0100 Subject: [PATCH 17/18] First Commit --- Week3/homework/step3.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/Week3/homework/step3.js b/Week3/homework/step3.js index ec51793e8..29c1c2c2a 100644 --- a/Week3/homework/step3.js +++ b/Week3/homework/step3.js @@ -1,9 +1,7 @@ 'use strict'; function createBase(base) { - return function(base) { return base + 6; - }; } const addSix = createBase(6); From 3c8ddff3ee048aa68d50ca1c7d7f2fa94b00bd3c Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 18 Feb 2019 22:06:25 +0100 Subject: [PATCH 18/18] First Commit --- Week3/homework/step3-bonus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week3/homework/step3-bonus.js b/Week3/homework/step3-bonus.js index 68492d4be..1ebeaddb7 100644 --- a/Week3/homework/step3-bonus.js +++ b/Week3/homework/step3-bonus.js @@ -3,7 +3,7 @@ const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; function makeUnique(arr) { -var myUniqueArray = []; +const myUniqueArray = []; arr.forEach(function(element) { if (myUniqueArray.indexOf(element) === -1) { myUniqueArray.push(element);