[CodeKata JS] Is your period late?
4512 ワード
Task
イカタでは、月経が遅いかどうかをテストする機能を作成します.
関数には、次の3つのパラメータがあります.
前日から今日までの日数がサイクル長より大きい場合は、
Initial Setting 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
イカタでは、月経が遅いかどうかをテストする機能を作成します.
関数には、次の3つのパラメータがあります.
last
-最後の日付を持つDate 객체
today
-確認日を持つDate 객체
cycleLength
-周期長Day
を表す整数前日から今日までの日数がサイクル長より大きい場合は、
true
を返します.そうでなければfalse
に戻ります.Initial Setting
function periodIsLate(last, today, cycleLength)
{
return false;
}
My Solutionconst 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 Userfunction periodIsLate(last, today, cycleLength)
{
return (today-last)/86400000>cycleLength
}
リンクReference
この問題について([CodeKata JS] Is your period late?), 我々は、より多くの情報をここで見つけました https://velog.io/@realryankim/CodeKata-JS-Is-your-period-lateテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol