Created
October 13, 2019 10:30
-
-
Save dawidjaniga/1fa9a13d7b734e73687cb733db8210bd to your computer and use it in GitHub Desktop.
This file contains 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
class LearingHoursCounter { | |
constructor({learningHoursPerDay}) { | |
this.learningHoursPerDay = learningHoursPerDay | |
} | |
sumCoursesTime () { | |
const elements = [...document.querySelectorAll('.meta')].map( | |
item => item.firstChild.data | |
) | |
let hoursSum = 0 | |
let minutesSum = 0 | |
const numbersRegExp = new RegExp(/\d+/, 'g') | |
elements.forEach(time => { | |
const [hours, minutes] = time.match(numbersRegExp) | |
hoursSum += Number(hours) | |
minutesSum += Number(minutes) | |
}) | |
const hoursFromMinutes = Math.floor(minutesSum / 60) | |
const restMinutes = minutesSum % 60 | |
hoursSum += hoursFromMinutes | |
minutesSum = restMinutes | |
return { | |
hours: hoursSum, | |
minutes: minutesSum | |
} | |
} | |
howManyDaysOfLearing(time) { | |
const minutesInHour = 60 | |
const minutesSum = time.hours * minutesInHour + time.minutes | |
return minutesSum / (minutesInHour * this.learningHoursPerDay) | |
} | |
display() { | |
console.log(`Assuming you'll be learing ${this.learningHoursPerDay} hours per days, it will take %d days`, this.howManyDaysOfLearing(this.sumCoursesTime())) | |
} | |
} | |
const OneHoursPerDay = new LearingHoursCounter({learningHoursPerDay: 1}) | |
const TwoHoursPerDay = new LearingHoursCounter({learningHoursPerDay: 2}) | |
const ThreeHoursPerDay = new LearingHoursCounter({learningHoursPerDay: 3}) | |
const FourHoursPerDay = new LearingHoursCounter({learningHoursPerDay: 4}) | |
OneHoursPerDay.display() | |
TwoHoursPerDay.display() | |
ThreeHoursPerDay.display() | |
FourHoursPerDay.display() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment