1function listToMatrix(list, elementsPerSubArray) {
2 var matrix = [], i, k;
3
4 for (i = 0, k = -1; i < list.length; i++) {
5 if (i % elementsPerSubArray === 0) {
6 k++;
7 matrix[k] = [];
8 }
9
10 matrix[k].push(list[i]);
11 }
12
13 return matrix;
14}
15
1myArr.reduce((rows, key, index) => (index % 3 == 0 ? rows.push([key])
2 : rows[rows.length-1].push(key)) && rows, []);
3