Categories
Development jQuery

print array in transpose format using jquery

I am little bit stuck in the below logic.

var t = new Array(),
  i = 1;
for (var s = 0; s < 7; s++) {
  t[s] = [];
  for (j = 0; j < 7; j++) {
    t[s][j] = i;
    if (i === 6) {
      i = 0;
    }
    i++;
  }
}
console.log(t);

In my tried logic i am getting array like below

0: [1,2,3,4,5,6,1]
1: [2,3,4,5,6,1,2]
2: [3,4,5,6,1,2,3]
3: [4,5,6,1,2,3,4]
4: [5,6,1,2,3,4,5]
5: [6,1,2,3,4,5,6]
6: [1,2,3,4,5,6,1]

But I want output

0: [1,2,3,4,5,6,0]
1: [2,3,4,5,6,0,1]
2: [3,4,5,6,0,1,2]
3: [4,5,6,0,1,2,3]
4: [5,6,0,1,2,3,4]
5: [6,0,1,2,3,4,5]
6: [0,1,2,3,4,5,6]

Looking for help.

Leave a Reply

Your email address will not be published. Required fields are marked *