Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 965 Bytes

is-your-period-late.md

File metadata and controls

33 lines (22 loc) · 965 Bytes

Is your period late? 8 Kyu

LINK TO THE KATA - FUNDAMENTALS DATE TIME

Description

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

Return true if the number of days passed from last to today is greater than cycleLength. Otherwise, return false.

Solution

const periodIsLate = (last, today, cycleLength) => {
  const numberDaysLast = last.getTime() / (1000 * 3600 * 24)
  const numberDaysToday = today.getTime() / (1000 * 3600 * 24)
  const diferenceDays = numberDaysToday - numberDaysLast

  return diferenceDays > cycleLength
}