提交 090e820e 编写于 作者: 幻灰龙's avatar 幻灰龙

Merge branch 'master' into 'master'

feat: 简单的一个字符中元音字母数量算法

See merge request !1
# 一个字符串作为输入返回该字符串中元音字母的数量
请编写一个函数 countVowels,该函数接受一个字符串作为输入,然后返回该字符串中元音字母的数量。
## 输入描述
一个字符串。
## 输出描述
一个数字,表示该字符串中元音字母的数量。
## 输入样例
console.log(countVowels('hello')); // 输出 2
## 输出样例
console.log(countVowels('javascript')); // 输出 3
console.log(countVowels('world')); // 输出 1
console.log(countVowels('')); // 输出 0
console.log(countVowels('aeiou')); // 输出 5
console.log(countVowels('AEIOU')); // 输出 5
console.log(countVowels('hjklmnpqrstvwxyz')); // 输出 0
console.log(countVowels('Hello World!')); // 输出 3
console.log(countVowels('To be or not to be, that is the question.')); // 输出13
console.log(countVowels('Brevity is the soul of wit.')); // 输出 8
## 提示
遍历字符串,依次检查每个字符是否是元音字母;
如果是,则将计数器加1;
最后返回计数器的值。
function countVowels(str) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
let count = 0;
for (let i = 0; i < str.length; i++) {
if (vowels.indexOf(str[i].toLowerCase()) !== -1) {
count++;
}
}
return count;
}
\ No newline at end of file
19
XLL
L
M
XLLLL
XLLLLL
L
XLLL
M
XLLLLL
M
S
XLLL
XLLL
XLLL
XLLL
S
S
S
S
S
XLLLLL
L
M
XLLL
M
XL
XL
XLLL
XL
S
XL
XL
XLLLLL
XLLLL
S
XL
L
XLLL
79
XLLLL
XLLLLL
XLL
XLLL
M
XL
S
XL
XLLLL
M
L
XLL
XLLLL
S
XL
XL
XL
XLLL
S
M
XLLLL
XLLL
XLLLL
L
XLLLL
XLL
XLLLL
XLLLLL
M
XL
XLLLLL
S
XLLLLL
XLLLLL
L
M
XL
XLLL
S
XLLL
XLLL
XLLLL
XLL
XLLLL
XLLLL
XLLLLL
S
XLLL
XLL
M
XLLLLL
L
XLL
XLLLLL
XLL
XLL
XLL
M
XLLLLL
XLLL
XL
XLLL
XLLLL
XL
M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