题目:
In this kata, we will make a function to test whether a period is late.
Our function will take three parameters:
last - The Date object with the date of the last period
today - The Date object with the date of the check
cycleLength - Integer representing the length of the cycle in days
If the today is later from last than the cycleLength, the function should return true. We consider it to be late if the number of passed days is larger than the cycleLength. Otherwise return false.
较好的解答:
function periodIsLate(last, today, cycleLength)
{
return (today-last)/86400000>cycleLength
}
var _MS_PER_DAY = 1000 * 60 * 60 * 24;
function periodIsLate(last, today, cycleLength)
{
return Math.floor((today - last) / _MS_PER_DAY) > cycleLength;
}
自己的解答:
function periodIsLate(last, today, cycleLength)
{
let month = today.getMonth()- last.getMonth();
if(month){
month = month * new Date(today.getYear(), today.getMonth(), 0).getDate()
}
return today.getDate() - last.getDate() + month > cycleLength ? true : false ;
}

创建一个函数检查月经周期是否延迟,根据最后月经日期、当前日期和周期长度判断。如果当前日期超过周期长度天数,则返回true,否则返回false。
523

被折叠的 条评论
为什么被折叠?



