1.6 KiB
1.6 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
5a23c84252665b21eecc7edc | Ultimo venerdì di ogni mese | 5 | 302299 | last-friday-of-each-month |
--description--
Scrivi una funzione che restituisce la data dell'ultimo venerdì di un dato mese per un dato anno.
--hints--
lastFriday
dovrebbe essere una funzione.
assert(typeof lastFriday == 'function');
lastFriday(2018, 1)
dovrebbe restituire un numero.
assert(typeof lastFriday(2018, 1) == 'number');
lastFriday(2018, 1)
dovrebbe restituire 26
.
assert.equal(lastFriday(2018, 1), 26);
lastFriday(2017, 2)
dovrebbe restituire 24
.
assert.equal(lastFriday(2017, 2), 24);
lastFriday(2012, 3)
dovrebbe restituire 30
.
assert.equal(lastFriday(2012, 3), 30);
lastFriday(1900, 4)
dovrebbe restituire 27
.
assert.equal(lastFriday(1900, 4), 27);
lastFriday(2000, 5)
dovrebbe restituire 26
.
assert.equal(lastFriday(2000, 5), 26);
lastFriday(2006, 6)
dovrebbe restituire 30
.
assert.equal(lastFriday(2006, 6), 30);
lastFriday(2010, 7)
dovrebbe restituire 30
.
assert.equal(lastFriday(2010, 7), 30);
lastFriday(2005, 8)
dovrebbe restituire 26
.
assert.equal(lastFriday(2005, 8), 26);
--seed--
--seed-contents--
function lastFriday(year, month) {
}
--solutions--
function lastFriday(year, month) {
var i, last_day;
i = 0;
while (true) {
last_day = new Date(year, month, i);
if (last_day.getDay() === 5) {
return last_day.getDate();
}
i -= 1;
}
}