Minutes to Hours and Minutes
Programming Basics · JavaScript
TASK
Problem
Given non-negative minutes `m`, print full hours and remaining minutes separated by a space.
EXAMPLE
Example
135
2 15
LIMITS
Constraints
All numeric input values fit in JavaScript `Number`.
LEARN
Theory for this problem
+
### Minutes to Hours and Minutes
Integer division separates higher decimal/time units, while `%` returns the remainder. These two operations let a program isolate digits or split a total number of seconds/minutes into components.
NEED HELP?
Hints
+
['Decide which part comes from division and which part comes from the remainder.', 'Verify the accumulator initial value and both loop boundaries; this is where off-by-one errors most often appear.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let m = Number(input);
console.log(Math.floor((m) / (60)), (((m) % (60)) + (60)) % (60));