let nowMonth = 2; // March
let futureMonth = nowMonth + 18;
console.log( months[ futureMonth % months.length ] ); // still outputs September, even though there isn't a 20th month
Worth noting that lots of languages refer to their months from 0-11, presumably for cool tricks like this.
I'm doing this right now in an app where each created item is assigned a color with ~15 predefined colors after which it will loop back around. Previously I was randomly generating a color and often getting similar shades back to back.
I am doing a job application challenge and I have to show a list of products. They didn't provide images, but I want to use stock photo images to give the page a nicer look. Some categories have 5 products, some have 1, others have 20. So I downloaded about 10 stock photos I like and now I can iterate that array by using the product's iterator.
0
u/[deleted] Mar 18 '19
[deleted]