function arr2DTo1D(arr2d: number[][]) {
const arr: number[] = new Array(arr2d.length * arr2d[0].length);
let k: number = 0;
for (let i: number = 0; i < arr2d.length; i++) {
for (let j: number = 0; j < arr2d[i].length; j++) {
arr[k++] = arr2d[i][j];
}
}
return arr;
}
const arr2d: number[][] = [
[ 5, 6, 1, 4 ],
[ 3, 8, 0, 2 ],
[ 9, 2, 7, 3 ]
];
const arr = arr2DTo1D(arr2d);
console.log(arr);
/*
run
[5, 6, 1, 4, 3, 8, 0, 2, 9, 2, 7, 3]
*/