From 488083fcf092867a84a33ad427db513b89a1df55 Mon Sep 17 00:00:00 2001 From: mohamdmahdi Date: Tue, 15 Jan 2019 00:52:07 +0100 Subject: [PATCH 1/2] homework week2 --- Week2/homework/maartjes-work.js | 17 ++++++++++++++--- Week2/homework/map-filter.js | 6 ++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index fc8c0e633..68eea801c 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -47,15 +47,26 @@ const maartjesHourlyRate = 20; function computeEarnings(tasks, hourlyRate) { // Replace this comment and the next line with your code - console.log(tasks, hourlyRate); + let rate = 0; + for (const task of tasks) { + const Total = task * hourlyRate; + rate += Total; + } + return rate; +} +function computeTasksInHours(maartjesTasks, celling) { + const marrtjeTasksInHours = maartjesTasks + .map(task => task.duration / 60) + .filter(task => task > celling); + return marrtjeTasksInHours; } // eslint-disable-next-line no-unused-vars -const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); +const earnings = computeEarnings(computeTasksInHours(maartjesTasks, 2), maartjesHourlyRate); // 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'}`); +console.log('Maartje has earned €' + Math.round(earnings * 100) / 100 + '.'); // Do not change or remove anything below this line module.exports = { diff --git a/Week2/homework/map-filter.js b/Week2/homework/map-filter.js index ab3c622d4..307cdeb89 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -2,11 +2,13 @@ function doubleOddNumbers(numbers) { // Replace this comment and the next line with your code - console.log(numbers); + const newNumber = myNumbers.filter(number => (number % 2 === 0 ? number : false)); + + return newNumber; } const myNumbers = [1, 2, 3, 4]; -console.log(doubleOddNumbers(myNumbers)); +console.log('Using the filter method :' + doubleOddNumbers(myNumbers)); // Do not change or remove anything below this line module.exports = { From 1aff6515963dae12d0958e8659a58d39ff1aec44 Mon Sep 17 00:00:00 2001 From: mohamdmahdi Date: Wed, 16 Jan 2019 11:41:55 +0100 Subject: [PATCH 2/2] homework week --- Week2/homework/maartjes-work.js | 25 +++++++++++++++---------- Week2/homework/map-filter.js | 3 +-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 68eea801c..1c33a8bca 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -45,28 +45,33 @@ const tuesday = [ const maartjesTasks = monday.concat(tuesday); const maartjesHourlyRate = 20; +function computeTasksInHours(maartjesTasksX, celling) { + const marrtjeTasksInHours = maartjesTasksX + .map(task => task.duration / 60) + .filter(task => task >= celling); + return marrtjeTasksInHours; +} + function computeEarnings(tasks, hourlyRate) { // Replace this comment and the next line with your code + const Taskhours = computeTasksInHours(tasks, 2); let rate = 0; - for (const task of tasks) { + for (const task of Taskhours) { const Total = task * hourlyRate; rate += Total; } return rate; + // eslint-disable-next-line no-unused-vars } -function computeTasksInHours(maartjesTasks, celling) { - const marrtjeTasksInHours = maartjesTasks - .map(task => task.duration / 60) - .filter(task => task > celling); - return marrtjeTasksInHours; -} -// eslint-disable-next-line no-unused-vars -const earnings = computeEarnings(computeTasksInHours(maartjesTasks, 2), maartjesHourlyRate); +const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); +const result = earnings.toFixed(2); + +// Math.round(rate * 100) / 100; // add code to convert `earnings` to a string rounded to two decimals (euro cents) -console.log('Maartje has earned €' + Math.round(earnings * 100) / 100 + '.'); +console.log('Maartje has earned €' + result + '.'); // Do not change or remove anything below this line module.exports = { diff --git a/Week2/homework/map-filter.js b/Week2/homework/map-filter.js index 307cdeb89..ba6e1c30f 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -2,8 +2,7 @@ function doubleOddNumbers(numbers) { // Replace this comment and the next line with your code - const newNumber = myNumbers.filter(number => (number % 2 === 0 ? number : false)); - + const newNumber = numbers.filter(number => (number % 2 === 1 ? number : false)).map(x => x + x); return newNumber; }