Skip to content

Instantly share code, notes, and snippets.

@Cst2989
Created October 22, 2021 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cst2989/6ff14fd528c92e91449917d1a7577c18 to your computer and use it in GitHub Desktop.
Save Cst2989/6ff14fd528c92e91449917d1a7577c18 to your computer and use it in GitHub Desktop.
list to matrix
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