How do I check for vowels in JavaScript?

前端 未结 10 891
忘了有多久
忘了有多久 2020-12-01 02:55

I\'m supposed to write a function that takes a character (i.e. a string of length 1) and returns true if it is a vowel, false otherwise. I came up with two functions, but do

10条回答
  •  执笔经年
    2020-12-01 03:21

    I created a simplified version using Array.prototype.includes(). My technique is similar to @Kunle Babatunde.

    const isVowel = (char) => ["a", "e", "i", "o", "u"].includes(char);
    
    console.log(isVowel("o"), isVowel("s"));

提交回复
热议问题