Created
January 24, 2020 16:43
-
-
Save Defite/ca5135269bc1d9559347055e529d615b to your computer and use it in GitHub Desktop.
Place counter under some weird business logic
This file contains 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
const steps = [31, 29, 31, 30, 31, 30]; | |
const year = []; | |
let modifiedYear = [] | |
// First date | |
const counterDate = 14; | |
// step is equal to month length | |
steps.forEach(count => { | |
year.push(Array(count).fill(0)) | |
}) | |
var newYearArr = year.flat(); | |
// Выставить дату первый раз | |
newYearArr[counterDate - 1] = 1; | |
steps.reduce((acc, step) => { | |
var result = acc + step; | |
newYearArr[result] = 1; | |
return result; | |
}, counterDate); | |
var chunkedArray = []; | |
steps.forEach((step, index) => { | |
chunkedArray.push(newYearArr.splice(0, step)) | |
}) | |
console.log(chunkedArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment