Created
October 29, 2019 12:17
-
-
Save KartaviK/47472b4d56740d4529bf99d41256b912 to your computer and use it in GitHub Desktop.
Separating days number on weeks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Separating days by week with init day setting | |
* | |
* @param days | |
* @param initDay | |
* @param initWeekDay | |
* @returns {Array[]} | |
*/ | |
function separateDaysByWeek(days, initDay, initWeekDay = 0) { | |
let result = [[]]; | |
let maxDay = days + initDay; | |
let week = 0; | |
let weekDays = initWeekDay; | |
for (let day = initDay; day < maxDay; day++) { | |
result[week].push(day); | |
weekDays++; | |
if (weekDays === 7) { | |
if (day + 1 === maxDay) { | |
break; | |
} | |
week++; | |
weekDays = 0; | |
result.push([]); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment