Capitalize letter in a string in order and create an array to store - JavaScript

We are required to write a JavaScript function that takes in a string and turns it into a Mexican Wave i.e. resembling string produced by successive captial letters in every word −

For example −

If the string is −

const str = 'edabit';

Then the output should be the following i.e. successive single capital letter −

const output = ["Edabit", "eDabit", "edAbit", "edaBit", "edabIt", "edabiT"];


Following is the code −

const str = 'edabit';
const replaceAt = function(index, char){
   let a = this.split("");
   a[index] = char;
   return a.join("");
String.prototype.replaceAt = replaceAt;
const createEdibet = word => {
   let array = word.split('')
   const res =, i) => {
      let a = word.replaceAt(i, letter.toUpperCase());
      return a;
   return res;

This will produce the following output on console −

[ 'Edabit', 'eDabit', 'edAbit', 'edaBit', 'edabIt', 'edabiT' ]