How to print text diagonally from left to right recursively in TypeScript

1 Answer

0 votes
function printTextDiagonallyRecursivelyLTR(spaces: string, text: string): void {
    if (text.length > 0) {
        console.log(spaces + text[0]);
        printTextDiagonallyRecursivelyLTR(spaces + " ", text.substring(1));
    }
}

printTextDiagonallyRecursivelyLTR("", "HELLO WORLD");



/*
run:

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

 



answered Apr 8 by avibootz

Related questions

...