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

Day02  深入了解 Lazy-load 的背後實作 - Intersection Observer API

Day02 深入了解 Lazy-load 的背後實作 - Intersection Observer API

W13_現代前端工具、JS 與 CSS 補充概念_學習筆記整理

W13_現代前端工具、JS 與 CSS 補充概念_學習筆記整理

Bootstrap 中的響應式中斷點

Bootstrap 中的響應式中斷點


Comments