Skip to content

Instantly share code, notes, and snippets.

@another-guy
Created April 25, 2024 19:50
Show Gist options
  • Save another-guy/589f71d3b71f98c4b1a3ff6fe6b3451f to your computer and use it in GitHub Desktop.
Save another-guy/589f71d3b71f98c4b1a3ff6fe6b3451f to your computer and use it in GitHub Desktop.
learn.cantrill.io - time
function sumUp(t) {
const classes = t.split('\n').filter(l => l?.length > 9);
const r = /\((?<minutes>\d+)\:(?<seconds>\d+)(\s\))/;
const totalSeconds = classes
// parse each line
.map(s => r.exec(s)?.groups)
// ignore unparsed
.filter(Boolean)
// convert to seconds
.map(({ minutes, seconds }) => ((+minutes) * 60 + (+seconds)))
// sum up all seconds
.reduce((a, b) => a + b, 0);
const totalHours = totalSeconds / 60 / 60;
return Math.ceil(totalHours) + ' hours ' + Math.ceil((totalHours % 1) * 60) + ' minutes';
}
/*
AWS Certified Solutions Architect - Associate (SAA-C03): '63 hours 8 minutes'
AWS Certified Solutions Architect - Professional '68 hours 7 minutes'
AWS Certified SysOps Administrator - Associate '66 hours 7 minutes'
AWS Certified Advanced Networking - Specialty '35 hours 12 minutes'
AWS Certified Security - Specialty '35 hours 57 minutes'
Tech Fundamentals '9 hours 16 minutes'
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment