Need a mathematician smarty pants please

I built an admin panel which has image upload… to avoid issues for my client when adding gallery images i added some auto choosing options.

So the gallery was always
Image 1 - Portrait
Image 2 - Landscape
And that sequence just repeated over and over again, so when my server action was cropping and resizing images for them it would know if it was cropping for a portrait or a landscape end result image. This was achieved pretty easily with the following.

((image_category.value == 'Gallery') && (image_position.value.toNumber() % 2 == 1)) ? 'Portrait' : 'Landscape'

This made all odd numbers = 1 so it was pretty easy to do considering all odd positions were Portrait and all evens were Landscape.

Now they asked for a change, and the new order will be
Image 1 - Landscape
Image 2 - Portrait
Image 3 - Portrait
Image 4 - Landscape
And that new sequence just repeats over and over.

Is there any mathematical way like that modulo operator idea to adjust my condition to make the new sequence auto choose L,P,P,L , L,P,P,L , L,P,P,L
I can not think of a way, but hoping someone is a maths boffin.

Community Page
Last updated: