У меня есть следующий массив:
a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
Я использую его для некоторых визуальных вещей, таких как:
1 2 3 4<br/>
5 6 7 8<br/>
9 10 11 12<br/>
13 14 15 16<br/>
Теперь я хочу отсортировать массив таким образом, чтобы иметь «зигзаг» при рендеринге позже.
// rearrange the array according to this schema
1 3 6 10
2 5 9 13
4 8 12 15
7 11 14 16
// the original array should look like this:
a = [1,5,2,9,6,3,13,10,7,4,14,11,8,15,12,16]
// the second index to draw should be the first index in the second row,
// which is represent by 5 in the original 1D Array
Да, сейчас я ищу умную формулу, чтобы сделать это
ticker = 0;
rows = 4; // can be n
cols = 4; // can be n
originalArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16];
newArray = [];
while(ticker < originalArray.length)
{
//do the magic here
ticker++;
}