Created
October 22, 2021 10:46
-
-
Save Cst2989/6ff14fd528c92e91449917d1a7577c18 to your computer and use it in GitHub Desktop.
list to matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const listToMatrix = (list) => { | |
let matrix = [], i, k; | |
for (i = 0, k = -1; i < list.length; i++) { | |
if (i % 2 === 0) { | |
k++; | |
matrix[k] = []; | |
} | |
matrix[k].push(list[i]); | |
} | |
return matrix; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment