// 将一维数组转为二维数组
<pre>
function listToMatrix(list, elementPerSubArray) {
var matrix = [],
i = void 0,
k = void 0;
for (i = 0, k = -1; i < list.length; i += 1) {
if (i % elementPerSubArray === 0) {
k += 1;
matrix[k] = [];
}
matrix[k].push(list[i]);
}
return matrix;
}
网友评论