How to convert a character (flatten) matrix to a single string in TypeScript

1 Answer

0 votes
function flattenMatrix(matrix: string[][]): string {
  return matrix.flat().join('');
}

function main(): void {
  const matrix: string[][] = [
    ['H', 'e', 'l', 'l', 'o'],
    [' ', 'W', 'o', 'r', 'l', 'd'],
    ['!']
  ];

  const output = flattenMatrix(matrix);
  console.log("Flattened string:", output);
}

main();




/*
run:

Flattened string: Hello World!

*/

 



answered Jan 10 by avibootz

Related questions

...