Last active
May 11, 2018 15:47
-
-
Save dotspencer/d25b0eb0813fda1dc64880db338a64b6 to your computer and use it in GitHub Desktop.
Hours worked script
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
var hoursWorked = ["10:03", "9:01", "8:58", "7:40"]; | |
var timePattern = /(\d+):(\d+)/; | |
var hours = hoursWorked.map(h => { | |
var match = h.match(timePattern); | |
var hours = parseInt(match[1]); | |
var min = parseInt(match[2]); | |
hours += (min / 60); | |
return hours; | |
}); | |
var total = hours.reduce((sum, h) => { | |
return sum + h; | |
}, 0); | |
var remainingHours = 40 - total; | |
var minLeft = (remainingHours % 1) | |
var hoursLeft = remainingHours - minLeft | |
minLeft = Math.round(minLeft * 60); | |
console.log(`You have ${hoursLeft} hours and ${minLeft} minutes left.`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment