0
I have a function that identifies the month through two entries, the initial month and also the difference that would be the maximum range of my array. At the same time there is another condition that in the case, limits my list to 6 values
var CountMes = 0;
function DataTabela(mesInicial, Diferenca) {
var Meses = [];
Meses.push(mesInicial);
while (CountMes < 5 && Diferenca > CountMes) {
CountMes++;
mesInicial++;
Meses.push(mesInicial);
}
alert(Meses.toString());
}
It works perfectly while we’re in the same year. My problem is, if my initial month entry is 11 (November) and my difference is 4, my list should have: November, December, January and February. However, as the account is on 12 basis and January would be equivalent to mesInicial = 1
, how can I model my function to be adaptable to year transitions?
Have you ever thought about working with a array containing integers from 1 to 12 and restart the search on that array if the input and difference calculation exceeds 12?
– Erlon Charles
Type, you find the position of the input in the array and then advance the boxes according to the difference, restarting the search in the array if it passes 12
– Erlon Charles