[CodeKata JS] Is your period late?


Task
イカタでは、月経が遅いかどうかをテストする機能を作成します.
関数には、次の3つのパラメータがあります.last-最後の日付を持つDate 객체today-確認日を持つDate 객체cycleLength-周期長Dayを表す整数
前日から今日までの日数がサイクル長より大きい場合は、trueを返します.そうでなければfalseに戻ります.
Initial Setting
function periodIsLate(last, today, cycleLength)
{
  return false;
}
My Solution
const periodIsLate = function(last, today, cycleLength) {
  const oneDay = 24 * 60 * 60 * 1000; // hours * minutes * seconds * milliseconds
  const diffDays = Math.round(Math.abs((today - last) / oneDay))
  
  return diffDays > cycleLength ? true : false;  
}
Solution 1 of Another User
function periodIsLate(last, today, cycleLength)
{
  return (today-last)/86400000>cycleLength
}
リンク
  • https://www.codewars.com/kata/578a8a01e9fd1549e50001f1/train/javascript
  • https://stackoverflow.com/questions/2627473/how-to-calculate-the-number-of-days-between-two-dates
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs