Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - Решение без Date() - с масив, тернарен оператор и няколко метода:
 - function solve(year, month, date) {
 - let day30 = [4, 6, 9, 11];
 - let monthDays = 0;
 - if (month === 2) {
 - if (year % 4 === 0) {
 - year % 100 !== 0 || year % 400 === 0 ? monthDays = 29 : monthDays = 28;
 - }
 - } else {
 - day30.includes(month) ? monthDays = 30 : monthDays = 31;
 - }
 - ++date > monthDays ? (date = 1) && month++ : date;
 - month === 13 ? (month = 1) && year++ : year;
 - console.log(year.toString().length !== 4 ? `${1900 + year}-${month}-${date}` : `${year}-${month}-${date}`);
 - }
 - Решение с Date(), малко Regex и няколко метода:
 - function nextDay(year, month, day){
 - let date = new Date(year, month - 1, day + 1);
 - date.setDate(date.getDate() + 1);
 - let output = date.toISOString().substring(0, 10).split('-');
 - console.log(`${output[0]}-${output[1].replace(/^0+/, '')}-${output[2].replace(/^0+/, '')}`);
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment