I have some checkboxes on a page that are organized in 3 columns. However they are alphabetically sorted and go across the rows instead.
What is currently happening:
A B C
D E F
G H I
What I want to happen:
A D G
B E H
C F I
Right now I've got this code to work it out but I feel super confused by what to do when theres a remainder in the array and I don't know how to include it into the sorting without messing it up:
organizedCheckboxesArea() {
let quotient = Math.floor(this.areas.length/3);
let remainder = this.areas.length % 3;
let organizedColumns = [];
for(let i = 0 ; i < quotient; i++) {
organizedColumns.push(this.areas[i]);
organizedColumns.push(this.areas[quotient + i]);
organizedColumns.push(this.areas[(quotient * 2) + i]);
}
return organizedColumns;
},
Its frustrating me a lot because I know the solution is simple I just can't think of it.
EDIT: this is not a 2 dimensional array. it is ['A', 'B', 'C', 'D' etc...].
Also for when there is a remainder, I want it to stack to the left two columms. ie ABCDEFGHIJ would make:
A E H
B F I
C G J
D
And ABCDEFGHIJK would make:
A E I
B F J
C G K
D H