Skip to content

Instantly share code, notes, and snippets.

@Defite
Created January 24, 2020 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Defite/ca5135269bc1d9559347055e529d615b to your computer and use it in GitHub Desktop.
Save Defite/ca5135269bc1d9559347055e529d615b to your computer and use it in GitHub Desktop.
Place counter under some weird business logic
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