Letter → Next Letter And Capitalize Vowels
This code still doesn't seem to be working. It has no errors anymore, but it only returns blank brackets like this {}. It is supposed to turn each letter in str into the next lette
Solution 1:
It looks like this method can by simplified to just a few calls to .replace
:
functionLetterChanges(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"
Or alternatively, a single call to .replace
, like this:
functionLetterChanges(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"
Post a Comment for "Letter → Next Letter And Capitalize Vowels"