Using only javascript, is it possible to add numbers within a specific sequence of numbers?
For example:
I have the numbers 1 to 12 (months of the year)
If I add 1 (January) + 3 (months), the result would be 4 (April).
But if I am in month 11 (November) and add 3, the result would be 14 (non-existent month in the sequence).
So I’m trying a solution so that when the sum reaches 12 (December), it returns to number 1 (January). So the sum of 11+3 would be 2 (February).
The example using dates is fictitious. I can’t use Date() as a reference because I’m looking for a solution for any random sequence of numbers in a row that I can iterate through.
I thought about the possibility of having an array, as shown in the example below:
let myArr = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec '];
myArr[10] //nov
Add 3 and return to position myArr[2] (feb)
But I’m not aware of any way to do this in an automated way with javascript.