Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
setDate getDate solution in Clear category for [old] The First Working Day by zoezed
"use strict";
function vacation(date, days) {
const d = new Date(date)
const addDays = (days) => d.setDate(d.getDate() + days)
addDays(days)
const day = d.getDay()
if (day === 0) addDays(1)
if (day === 6) addDays(2)
return d.toJSON().slice(0,10)
}
var assert = require('assert');
if (!global.is_checking) {
console.log("Example:");
console.log(vacation('2018-07-01', 14));
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(vacation('2018-07-01', 14), '2018-07-16')
assert.equal(vacation('2018-02-19', 10), '2018-03-01')
assert.equal(vacation('2000-02-28', 5), '2000-03-06')
assert.equal(vacation('1999-12-20', 14), '2000-01-03')
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Feb. 23, 2020