solution.js 248 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11
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;
  }