I would like to ask for efficient way to create such array:
[
1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3
...
n, n, n, n, n, n
]
Every 6 items the number is added 1++.
function createFaces(n){
var array = [];
var l = 1;
while(n > 0){
for(var i = 0; i < 6; i++){
array.push(l)
}
l++;
n--;
}
return array;
}
i=6throughi=6*n+5, and pushingi/6to the array. Similarly, you could eliminate one of your outer indices. That's all nearly pointless micro-optimization though.