I recently took a coding test for a promotion at work. This was one of the tasks I really struggled with and was wondering what is the best way to do this. I used a load of if and if else, not the cleanest solution but got the job done.
The question I was asked was:
Format 4 numbers into a 24-hour time (00:00), finding the maximum (latest) time possible, taking into account that the max hours would be 23 and the max minutes would be 59. If not possible, return NOT POSSIBLE.
So for example:
6, 5, 2, 0 would be 20:56
3, 9, 5, 0 would be 09:53
7, 6, 3, 8 would be NOT POSSIBLE
The example function that had to return the time or string looked like this, A, B, C, D being a different number from the comma-separated list above:
function generate(A, B, C, D) {
// Your code here
}
How would people tackle this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…