functioncharactersIndexes(string){returnstring.split("").reduce(function(indexes,character,index){if(!/\s/.test(character)){indexes.push(index);}returnindexes},[]);}functionupperCaseAt(index,string){returnstring.split("").map(function(character,position){if(position===index){returncharacter.toUpperCase();}returncharacter;}).join("");}functionwave(input){returncharactersIndexes(input).map((index)=>upperCaseAt(index,input));}console.log(wave("hello"));// [ 'Hello', 'hEllo', 'heLlo', 'helLo', 'hellO' ]console.log(wave("h e l l o"));// [ 'H e l l o', 'h E l l o', 'h e L l o', 'h e l L o', 'h e l l O' ]
JavaScript
Playground
Play with it on Repl.it.
expect(received).toEqual(expected) // deep equality