Answers for "javascript convert array to matrix"

0

javascript convert array to matrix

function listToMatrix(list, elementsPerSubArray) {
    var matrix = [], i, k;

    for (i = 0, k = -1; i < list.length; i++) {
        if (i % elementsPerSubArray === 0) {
            k++;
            matrix[k] = [];
        }

        matrix[k].push(list[i]);
    }

    return matrix;
}
Posted by: Guest on January-27-2021

Code answers related to "javascript convert array to matrix"

Code answers related to "Javascript"

Browse Popular Code Answers by Language