curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69738771fb5a7b8b24cca2a1.md
Given an array of your login logs, determine whether you have met your digital detox goal.
Each log is a string in the format "YYYY-MM-DD HH:mm:ss".
You have met your digital detox goal if both of the following statements are true:
digitalDetox(["2026-02-01 08:00:00", "2026-02-01 12:30:00"]) should return true.
assert.isTrue(digitalDetox(["2026-02-01 08:00:00", "2026-02-01 12:30:00"]));
digitalDetox(["2026-02-01 04:00:00", "2026-02-01 07:30:00"]) should return false.
assert.isFalse(digitalDetox(["2026-02-01 04:00:00", "2026-02-01 07:30:00"]));
digitalDetox(["2026-01-31 08:21:30", "2026-01-31 14:30:00", "2026-02-01 08:00:00", "2026-02-01 12:30:00"]) should return true.
assert.isTrue(digitalDetox(["2026-01-31 08:21:30", "2026-01-31 14:30:00", "2026-02-01 08:00:00", "2026-02-01 12:30:00"]));
digitalDetox(["2026-01-31 10:40:21", "2026-01-31 15:19:41", "2026-01-31 21:49:50", "2026-02-01 09:30:00"]) should return false.
assert.isFalse(digitalDetox(["2026-01-31 10:40:21", "2026-01-31 15:19:41", "2026-01-31 21:49:50", "2026-02-01 09:30:00"]));
digitalDetox(["2026-02-05 10:00:00", "2026-02-01 09:00:00", "2026-02-03 22:15:00", "2026-02-02 12:10:00", "2026-02-02 07:15:00", "2026-02-04 09:45:00", "2026-02-01 16:50:00", "2026-02-03 09:30:00"]) should return true.
assert.isTrue(digitalDetox(["2026-02-05 10:00:00", "2026-02-01 09:00:00", "2026-02-03 20:15:00", "2026-02-02 12:10:00", "2026-02-02 07:15:00", "2026-02-04 09:45:00", "2026-02-01 16:50:00", "2026-02-03 09:30:00"]));
digitalDetox(["2026-02-05 10:00:00", "2026-02-01 09:00:00", "2026-02-03 22:15:00", "2026-02-02 12:10:00", "2026-02-02 07:15:00", "2026-02-04 01:45:00", "2026-02-01 16:50:00", "2026-02-03 09:30:00"]) should return false.
assert.isFalse(digitalDetox(["2026-02-05 10:00:00", "2026-02-01 09:00:00", "2026-02-03 22:15:00", "2026-02-02 12:10:00", "2026-02-02 07:15:00", "2026-02-04 01:45:00", "2026-02-01 16:50:00", "2026-02-03 09:30:00"]));
function digitalDetox(logs) {
return logs;
}
function digitalDetox(logs) {
if (logs.length === 0) return true;
const times = logs
.map(log => new Date(log.replace(" ", "T") + "Z").getTime())
.sort((a, b) => a - b);
const ONE_DAY = 24 * 60 * 60 * 1000;
const FOUR_HOURS = 4 * 60 * 60 * 1000;
for (let i = 1; i < times.length; i++) {
if (times[i] - times[i - 1] < FOUR_HOURS) {
return false;
}
}
const dailyCounts = {};
for (const time of times) {
const day = new Date(time).toISOString().slice(0, 10);
dailyCounts[day] = (dailyCounts[day] || 0) + 1;
if (dailyCounts[day] > 2) {
return false;
}
}
return true;
}