Skip to content

Instantly share code, notes, and snippets.

@dotspencer
Last active May 11, 2018 15:47
Show Gist options
  • Save dotspencer/d25b0eb0813fda1dc64880db338a64b6 to your computer and use it in GitHub Desktop.
Save dotspencer/d25b0eb0813fda1dc64880db338a64b6 to your computer and use it in GitHub Desktop.
Hours worked script
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