How to convert a matrix of numbers to a string in TypeScript

1 Answer

0 votes
const matrix: number[][] = [
  [4, 7, 9, 18, 29, 0],
  [1, 9, 18, 99, 4, 3],
  [9, 17, 89, 2, 7, 5],
  [19, 49, 6, 1, 9, 8],
  [29, 4, 7, 9, 18, 6]
];

const matrixString: string = matrix
  .map(row => row.join(" "))
  .join(" ");

console.log(matrixString);



/*
run:

"4 7 9 18 29 0 1 9 18 99 4 3 9 17 89 2 7 5 19 49 6 1 9 8 29 4 7 9 18 6" 

*/

 



answered Jan 9 by avibootz
...