dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
70 lines
1.7 KiB
Markdown
70 lines
1.7 KiB
Markdown
---
|
|
id: 69a890af247de743333bd4d0
|
|
title: "Challenge 227: Cooldown Time"
|
|
challengeType: 28
|
|
dashedName: challenge-227
|
|
---
|
|
|
|
# --description--
|
|
|
|
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.
|
|
|
|
- Both timestamps will be given the format: `"YYYY-MM-DDTHH:MM:SS"`, for example `"2026-03-25T14:00:00"`. Note that the time is 24-hour clock.
|
|
- A user must wait at least 48 hours before retaking an exam.
|
|
|
|
# --hints--
|
|
|
|
`canRetake("2026-03-23T08:00:00", "2026-03-25T14:00:00")` should return `true`.
|
|
|
|
```js
|
|
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`.
|
|
|
|
```js
|
|
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`.
|
|
|
|
```js
|
|
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`.
|
|
|
|
```js
|
|
assert.isFalse(canRetake("2026-03-23T11:50:00", "2026-03-25T11:49:59"));
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
function canRetake(finishTime, currentTime) {
|
|
|
|
return finishTime;
|
|
}
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
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;
|
|
}
|
|
```
|