curriculum/challenges/english/blocks/daily-coding-challenges-javascript/698a1a73ade5ac0e19180fa1.md
Given a start date and an end date, return the number of business days between the two.
"YYYY-MM-DD".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);
function countBusinessDays(start, end) {
return start;
}
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;
}