Advertisement
dabidabidesh

Nex Day без Date

Jun 10th, 2020
2,741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //6 Exercise: Basic Syntax, Conditional Statements and Loops/More Exercise/03. Next Day.js
  2. nextDay1 = (year, month, day) => {
  3.   'use strict'
  4.  
  5.   let yearNext = year
  6.   let monthNext = month
  7.   let dayNext = day
  8.  
  9.   if (year <= 99 && year >= 0)
  10.     yearNext += 1900
  11.  
  12.   const isLeapYear = (year) => ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) ? true : false
  13.  
  14.   let months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  15.  
  16.   if (isLeapYear(year))
  17.     months[1] = 29
  18.  
  19.   if (month === 12 && day === 31) {
  20.     yearNext = ++yearNext
  21.     monthNext = 1
  22.     dayNext = 1
  23.   } else if (day === months[month - 1]) {
  24.     monthNext = ++month
  25.     dayNext = 1
  26.   } else {
  27.     dayNext = ++day
  28.   }
  29.  
  30.   console.log(`${yearNext}-${monthNext}-${dayNext}`)
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement