curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69a890af247de743333bd4d0.md
Given two timestamps, the first representing when a user finished an exam, and the second representing the current time, determine whether the user can take an exam again.
"YYYY-MM-DDTHH:MM:SS", for example "2026-03-25T14:00:00". Note that the time is 24-hour clock.canRetake("2026-03-23T08:00:00", "2026-03-25T14:00:00") should return true.
assert.isTrue(canRetake("2026-03-23T08:00:00", "2026-03-25T14:00:00"));
canRetake("2026-03-24T14:00:00", "2026-03-25T10:00:00") should return false.
assert.isFalse(canRetake("2026-03-24T14:00:00", "2026-03-25T10:00:00"));
canRetake("2026-03-23T09:25:00", "2026-03-25T09:25:00") should return true.
assert.isTrue(canRetake("2026-03-23T09:25:00", "2026-03-25T09:25:00"));
canRetake("2026-03-23T11:50:00", "2026-03-25T11:49:59") should return false.
assert.isFalse(canRetake("2026-03-23T11:50:00", "2026-03-25T11:49:59"));
function canRetake(finishTime, currentTime) {
return finishTime;
}
function canRetake(finishTime, currentTime) {
function parse(ts) {
const parts = ts.split(/[-T:]/).map(Number);
const [y, m, d, h, min, s] = parts;
return Date.UTC(y, m - 1, d, h, min, s);
}
const finishMs = parse(finishTime);
const currentMs = parse(currentTime);
const cooldown = 48 * 60 * 60 * 1000;
return currentMs - finishMs >= cooldown;
}