Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
getDate solution in Clear category for Birthday Party by Sim0000
import assert from "assert";
function birthdayParty(birthday: Date): Date {
const offset = [0, 5, 4, 3, 2, 1, 0];
birthday.setDate(birthday.getDate() + offset[birthday.getDay()]);
return birthday;
}
console.log("Example:");
console.log(birthdayParty(new Date(2022, 0, 5)));
// These "asserts" are used for self-checking
assert.deepStrictEqual(
birthdayParty(new Date(2022, 0, 5)),
new Date(2022, 0, 8)
);
assert.deepStrictEqual(
birthdayParty(new Date(2022, 1, 21)),
new Date(2022, 1, 26)
);
assert.deepStrictEqual(
birthdayParty(new Date(2022, 2, 26)),
new Date(2022, 2, 26)
);
assert.deepStrictEqual(
birthdayParty(new Date(2022, 3, 17)),
new Date(2022, 3, 17)
);
assert.deepStrictEqual(
birthdayParty(new Date(2022, 2, 30)),
new Date(2022, 3, 2)
);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
Nov. 19, 2021
Comments: