I can't seem to figure it out how to make a wave from a string in Javascript.
Rules:
- The input will always be lower case string.
- Ignore whitespace.
Expected result:
wave("hello") => ["Hello", "hEllo", "heLlo", "helLo", "hellO"]
wave (" h e y ") => [" H e y ", " h E y ", " h e Y "]
wave ("") => []
This is as far as I got. Current code will give me an answer ["hello", "hello", "hello", "hello", "hello"]. I'm thinking using second for loop and somehow capitalize each new letter but I'am stumped. Also I would appreciate if answer would avoid using loop inside loop O(n^2). Because of BIG O Scalability.
const wave = (str) => {
    if(typeof str === 'string' && str === str.toLowerCase()){
       for (let index = 0; index < str.length; index++) {
        array.push(str);
    }
    for (let index = 0; index < str.length; index++) {
            console.log(array);   
    }
    }else{
        alert(`${str} is either not a string or not lowercase`);
    }
}
wave("hello");
 
     
     
     
     
     
    