Imagine I have an array:
A = Array(1, 2, 3, 4, 5, 6, 7, 8, 9);
And I want it to convert into 2-dimensional array (matrix of N x M), for ins
Short answer use:
const gridArray=(a,b)=>{const d=[];return a.forEach((e,f)=>{const h=Math.floor(f/b);d[h]=d[h]||[],d[h][f%b]=a[f]}),d};
Where:
a: is the array b: is the number of columns
Long answer you can read the article:
How to convert an array of length ‘n’ to array grid