字母→下一个字母和大写元音 [英] Letter → next letter and capitalize vowels
问题描述
{}
的空括号。它应该把 str
中的每个字母变成下一个字母,并大写每个元音。任何想法?$ b $ pre $
函数LetterChanges(str){
str = str.split(); // split ()字符串到数组
for(var i = 0; i< str.length; i ++){// for循环检查每个字母
if(str [i] .match(/ [ay] / i)){
str [i] = String.fromCharCode(str [i] .charCodeAt(0)+1);
} else if(str [i] .match(z)){
str [i] =a; $ str $ {
}
if(str [i] .match(/ [aeiou] / i)){
str [i] = str [i] .toUpperCase
}
}
str = str.join();
//通过在字母表中加入修饰字母
//将每个元音大写
// join()字符串
return str;
简化为只需几次调用 <$ c 或者,对 This code still doesn't seem to be working. It has no errors anymore, but it only returns blank brackets like this
It looks like this method can by simplified to just a few calls to Or alternatively, a single call to
这篇关于字母→下一个字母和大写元音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ p $ lt; code>函数LetterChanges(str){
返回str
.replace(/ [ay] |(z)/ gi,function(c,z){return z?'a':String.fromCharCode(c.charCodeAt(0)+1);} )
.replace(/ [aeiou] / g,function(c){return x.toUpperCase();});
}
LetterChanges(abcdefgxyz);
//bcdEfghyzA
.replace
,像这样:
$ p $函数LetterChanges(str){
return str .replace(/(z)|([dhnt])| [ay] / gi,函数(c,z,v){
c = z?'A':String.fromCharCode(c.charCodeAt +1);
return v?c.toUpperCase():c;
})
}
LetterChanges(abcdefgxyz);
//bcdEfghyzA
{}
. It is supposed to turn each letter in str
into the next letter and capitalize each vowel. Any ideas?function LetterChanges(str) {
str = str.split("");//split() string into array
for(var i=0;i<str.length;i++){//for loop that checks each letter
if(str[i].match(/[a-y]/i)){
str[i]=String.fromCharCode(str[i].charCodeAt(0)+1);
}else if(str[i].match("z")){
str[i] = "a";
}
if(str[i].match(/[aeiou]/i)){
str[i] = str[i].toUpperCase();
}
}
str = str.join("");
//modifies letter by adding up in alphabet
//capitalizes each vowel
//join() string
return str;
}
.replace
:function LetterChanges(str) {
return str
.replace(/[a-y]|(z)/gi, function(c, z) { return z ? 'a' : String.fromCharCode(c.charCodeAt(0)+1); })
.replace(/[aeiou]/g, function(c) { return x.toUpperCase(); });
}
LetterChanges("abcdefgxyz");
// "bcdEfghyzA"
.replace
, like this:function LetterChanges(str) {
return str.replace(/(z)|([dhnt])|[a-y]/gi, function(c, z, v) {
c = z ? 'A' : String.fromCharCode(c.charCodeAt(0)+1);
return v ? c.toUpperCase() : c;
})
}
LetterChanges("abcdefgxyz");
// "bcdEfghyzA"