This repository was archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 328
Week2 #295
Closed
Closed
Week2 #295
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d6bc65b
Some more map, filter and =>, a program that doubles the odd numbers …
1fbde9d
Update and rename week2.js to ghufran/week2.js
ghifo 7ff0b75
Update week2.js
ghifo 433d0d7
Update week2.js
ghifo 3412b57
Update and rename week2.js to map-filter.js
ghifo b1448be
Create maartjes-work.js
ghifo f383e8e
Update map-filter.js
ghifo 7d15291
Update maartjes-work.js
ghifo 6e722a5
Update map-filter.js
ghifo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
|
||
const monday = [ | ||
{ | ||
name: 'Write a summary HTML/CSS', | ||
duration: 180, | ||
}, | ||
{ | ||
name: 'Some web development', | ||
duration: 120, | ||
}, | ||
{ | ||
name: 'Fix homework for class10', | ||
duration: 20, | ||
}, | ||
{ | ||
name: 'Talk to a lot of people', | ||
duration: 200, | ||
}, | ||
]; | ||
|
||
const tuesday = [ | ||
{ | ||
name: 'Keep writing summary', | ||
duration: 240, | ||
}, | ||
{ | ||
name: 'Some more web development', | ||
duration: 180, | ||
}, | ||
{ | ||
name: 'Staring out the window', | ||
duration: 10, | ||
}, | ||
{ | ||
name: 'Talk to a lot of people', | ||
duration: 200, | ||
}, | ||
{ | ||
name: 'Look at application assignments new students', | ||
duration: 40, | ||
}, | ||
]; | ||
/* cSpell: disable */ | ||
const maartjesTasks = monday.concat(tuesday); | ||
const maartjesHourlyRate = 20; | ||
|
||
function computeEarnings(tasks, hourlyRate) { | ||
// turn mins to hours | ||
const duration = tasks.map(task => task.duration / 60); | ||
return { ...task, duration: hours }; | ||
}; | ||
|
||
// remove less than 2 hours | ||
const filteredHour = duration.filter(elem => elem.duration >= 2); | ||
// earnings for the duration less than 2 hours | ||
return filteredHour.reduce((acc, elem) => { | ||
acc += elem.duration * hourlyRate; | ||
return acc; | ||
}, 0); | ||
} | ||
console.log(computeEarnings(maartjesTasks, maartjesHourlyRate)); | ||
|
||
const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); | ||
|
||
// set the decimal nrs to have only two values | ||
const roundEuros = earnings.toFixed(2); // 373.33333333333337 | ||
|
||
// call the value of toFixed(2) | ||
console.log(`Maartje has earned €${roundEuros}`); // Maartje has earned €373.33 | ||
|
||
module.exports = { | ||
maartjesTasks, | ||
maartjesHourlyRate, | ||
computeEarnings, | ||
}; | ||
/* cSpell: enable */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
function doubleOddNumbers(num) { | ||
num = num.filter(n => n % 2 !== 0).map(number => number * 2); | ||
return num; | ||
} | ||
|
||
const myNumbers = [1, 2, 3, 4]; | ||
console.log(doubleOddNumbers(myNumbers)); // [2, 6] the double of [1,3] | ||
|
||
module.exports = { | ||
myNumbers, | ||
doubleOddNumbers, | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.