The Situation
I have a certain amount of squares. I want these square to always from a square like grid but it can't have any empty spaces. I'd use JavaScript to do this. The grid would be stored like so
var gridLayout = [[1, 2], [3, 4]];
This would result in this grid
The Problem
If I have 16 squares it would result with
var gridLayout = [[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12],[13, 14, 15, 16]];
And the visual
Now all that's easy to do, but what if there's 3 squares? I'd like it to do something like this, favoring the horizontal over the vertical layout.
var gridLayout = [[1, 2, 3]];
with the visual
If I had 8 squares it couldn't make the perfect square so I'd like to be
var gridLayout = [[1, 2, 3, 4], [5, 6, 7, 8]];
And the visual
What I've tried
I've looked at this but it seems to be working with rectangles instead of squares. I also have a very hard time following without the visuals of what they want.
I have also looked at this which is kinda similar but seem to be a bit irrelevant to my situation.
Conclusion
How would I create the gridLayout
in such a way as what I want? Any help is appreciated.