Drill

ProblemsJavaScript › machines

Total hours a machine ran

mediummachinesJavaScript

A machine records operations as start and end minutes past midnight. Convert the whole running total into whole hours.

runHours(operations: list<Operation>) → int

Solve it in the editor →

Where you start

function runHours(operations) {
  
}

Worked examples

CallResult
runHours([{"start":0,"end":60},{"start":600,"end":900}])6
runHours([{"start":540,"end":600}])1
runHours([])0
runHours([{"start":0,"end":30}])0

Hint

Sum the minute spans, then integer-divide the total by sixty.

Reference solution in JavaScript
function runHours(operations) {
  let total = 0;
  for (const o of operations) total += o.end - o.start;
  return Math.floor(total / 60);
}

The same problem in another language

More machines problems in JavaScript