按字母顺序大写字符串并创建要存储的数组-JavaScript
我们需要编写一个JavaScript函数,该函数接受一个字符串并将其转换为墨西哥波,即类似于每个单词中连续大写字母产生的字符串-
例如-
如果字符串是-
const str = 'edabit';
然后输出应为以下内容,即连续的单个大写字母-
const output = ["Edabit", "eDabit", "edAbit", "edaBit", "edabIt", "edabiT"];
示例
以下是代码-
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));这将在控制台上产生以下输出-
[ 'Edabit', 'eDabit', 'edAbit', 'edaBit', 'edabIt', 'edabiT' ]
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志