skip to Main Content

Help me solve this is there some one can solve this?? im stuck

let word = ‘foxie’
//output
e
ei
xie
eixo
foxie

example 2:
```javascript
let word = '3oz4spoon'
//output 
n
no
oon
noop
spoon
noops4
z4spoon
noops4zo
3oz4spoon

2

Answers


  1. let word = "foxie";
    
     function reverseString(string) {
        return string.split("").reverse().join("");
     }
    
     for (let i = 1; i <= word.length; i++) {
       
       if (i === word.length) {
          console.log(word);
       } else {
          console.log(reverseString(word.slice(word.length - i)));
       }
     }
    
    // output:
       e 
       ei 
       eix 
       eixo 
       foxie
    
    Login or Signup to reply.
  2. function printPyramid(word, index = 0) {
      if (index % 2 === 0) {
        console.log(word.slice(word.length - index - 1));
      } else {
        console.log(word.slice(word.length - index - 1).split('').reverse().join(''));
      }
      if (word.length === index + 1) {
        return;
      }
      printPyramid(word, index + 1)
    }
    
    printPyramid('foxie')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search