Mexican Wave

·

1 min read

Task:
Create a function that turns a string into a Mexican Wave. You will be passed a string and you must return that string in an array where an uppercase letter is a person standing up.

let mexicanWave = str.slice(0, i) + str[i].toUpperCase() + str.slice(i + 1);

Above code aims to create a string where one character is capitalized (turned into uppercase), and the rest of the string is unchanged.

Let's break it down:

  1. str.slice(0, i): This is creating a new string that includes the characters from the start of the original string (str) up to but not including the ith character. slice is a method provided by JavaScript's String prototype that returns a portion of the string.

  2. str[i].toUpperCase(): This is getting the ith character from the original string (str[i]) and capitalizing it using the toUpperCase method, also provided by the String prototype.

  3. str.slice(i + 1): This is creating a new string that includes all characters from the original string (str) starting from the character after the ith character.

  4. The + operators are then concatenating these three strings together to form a new string. The ith character of this new string is capitalized, and the rest of the string is the same as the original string.