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
1.6 KiB
1.6 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 698a1a73ade5ac0e19180fa1 | Challenge 198: Business Day Count | 28 | challenge-198 |
--description--
Given a start date and an end date, return the number of business days between the two.
- Given dates are in the format
"YYYY-MM-DD". - Weekdays are business days (Monday through Friday).
- Weekends are not business days (Saturday and Sunday).
- Include both the start and end dates when counting.
--hints--
countBusinessDays("2026-02-24", "2026-02-26") should return 3.
assert.equal(countBusinessDays("2026-02-24", "2026-02-26"), 3);
countBusinessDays("2026-02-24", "2026-02-28") should return 4.
assert.equal(countBusinessDays("2026-02-24", "2026-02-28"), 4);
countBusinessDays("2026-02-21", "2026-03-01") should return 5.
assert.equal(countBusinessDays("2026-02-21", "2026-03-01"), 5);
countBusinessDays("2026-03-08", "2026-03-17") should return 7.
assert.equal(countBusinessDays("2026-03-08", "2026-03-17"), 7);
countBusinessDays("2026-02-24", "2027-02-24") should return 262.
assert.equal(countBusinessDays("2026-02-24", "2027-02-24"), 262);
--seed--
--seed-contents--
function countBusinessDays(start, end) {
return start;
}
--solutions--
function countBusinessDays(start, end) {
const startDate = new Date(start + "T00:00:00Z");
const endDate = new Date(end + "T00:00:00Z");
let count = 0;
let current = new Date(startDate);
while (current <= endDate) {
const day = current.getUTCDay();
if (day !== 0 && day !== 6) count++;
current.setUTCDate(current.getUTCDate() + 1);
}
return count;
}