How to print text diagonally from left to right in TypeScript

1 Answer

0 votes
function printDiagonalTextLTR(text: string): string {
    let output: string = "";

    for (let i: number = 0; i < text.length; i++) {
        output += " ".repeat(i) + text[i] + "\n";
    }

    return output;
}

console.log(printDiagonalTextLTR("HELLO WORLD"));

 
 
/*
run:
H
 E
  L
   L
    O
      
      W
       O
        R
         L
          D
 
*/

 



answered Apr 8 by avibootz
...