- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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"];
Example
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 = array.map((letter, i) => { let a = word.replaceAt(i, letter.toUpperCase()); return a; }); return res; } console.log(createEdibet(str));
This will produce the following output on console −
[ 'Edabit', 'eDabit', 'edAbit', 'edaBit', 'edabIt', 'edabiT' ]
- Related Articles
- How to capitalize the first letter of each word in a string using JavaScript?
- Using a recursive function to capitalize each word in an array in JavaScript
- Capitalize only the first letter after colon with regex and JavaScript?
- Array filtering using first string letter in JavaScript
- Capitalize first letter of a column in Pandas dataframe
- How to convert/store a string of numbers in to an array in java?
- How to create an ordered array from values that have an order number in JavaScript?
- How to capitalize a string in Python?
- Pandas dataframe capitalize first letter of a column
- Finding missing letter in a string - JavaScript
- How to create a string by joining the elements of an array in JavaScript?
- Loop through an index of an array to search for a certain letter in JavaScript
- string capitalize() in Python
- Mapping the letter of a string to an object of arrays - JavaScript
- How to store string array in Java JList?

Advertisements