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

1 Answer

0 votes
function printTextDiagonallyRecursivelyLTR(spaces, text) {
    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

...