Problems › JavaScript › scheduling
Total minutes scheduled
A weekly grid lists every shift as a start and end in minutes past midnight. Add up the committed hours.
- A shift always ends after it starts.
- An empty grid is an empty week: zero minutes.
shiftTotal(shifts: list<Shift>) → int
Where you start
function shiftTotal(shifts) {
}
Worked examples
| Call | Result |
|---|---|
shiftTotal([{"start":480,"end":900},{"start":900,"end":1080}]) | 600 |
shiftTotal([{"start":0,"end":1440}]) | 1440 |
shiftTotal([]) | 0 |
shiftTotal([{"start":600,"end":600}]) | 0 |
Hint
Sum of (end - start).
Reference solution in JavaScript
function shiftTotal(shifts) {
let total = 0;
for (const s of shifts) total += s.end - s.start;
return total;
}