javascript - Mathemmatical formula for incremental breakdowns -
i have dialog displays buttons according users settings. want have buttons layed out in best sequence of rows of 6. meaning, if user entered 1-6 entries, there should 1 row of 6 buttons. if entered 7 entries, shouldn't 6 on row 1 , 1 on row 2, rather, 4 on row 1 , 3 on row 2. if entered 8, should have 4 buttons on each row , on.....
being seasoned developer, feel little dumb this.... having difficulty figuring out correct method of finding out these numbers programmatically.
if can me appreciate it
thanks, david
if a / b
integer division , a % b
remainder of division of a
b
, need
rows = (buttons + 5) / 6
rows of buttons. can divide number of rows find best partitioning. if want minimize absolute difference of row lengths, i-th line (zero-based) example contain
buttons_in_line[i] = buttons / rows + (i < buttons % rows ? 1 : 0)
buttons. e.g. 22 buttons following layout:
# # # # # # # # # # # # # # # # # # # # # #
or 19 buttons:
# # # # # # # # # # # # # # # # # # #
Comments
Post a Comment