JavaScript, boon and bane

I’m coming up with a way to shuffle an infinite number of pages for double sided printing, in cut stacks, 5up on a sheet with a Dutch cut. This is taking time.