42 Vowel Count 7 kyu


Posted by mijouhsieh on 2024-01-04

7 kyu Vowel Count

題目說明:

函式帶入字串判斷有幾個母音(a,e,i,o,u)

code
export class Kata {
  static getCount(str: string): number {
    //code
    const lowerCaseStr = str.trim().toLowerCase();
    const regex = /[aeiou]/g;
    const matches = lowerCaseStr.match(regex);

    if (matches) {
      return matches.length;
    } else {
      return 0;
    }
  }
}

#TypeScript #string.match() #RegEx







Related Posts

Q&A [1]:有關環境與安裝

Q&A [1]:有關環境與安裝

練習讓我們完成各種夢想 — 刻意練習

練習讓我們完成各種夢想 — 刻意練習

人人都會的 Android Apk 反編譯

人人都會的 Android Apk 反編譯


Comments