Below is a code snippet I have:
for ( let i = 1; i <= 12; i++ ) {
console.log(i % 4);
}
This code produces the following output:
1
2
3
0
1
2
3
0
1
2
3
0
I want to modify the pattern (i % 4
) so that it outputs the following sequence instead:
1
1
1
1
2
2
2
2
3
3
3
3
I am looking for a way to achieve this without introducing additional variables, rather by adjusting the pattern within the console.log
statement to produce the desired sequence.
The sequence should increment by 1 every 4 iterations and should be applicable for more than just 12 iterations.