更新时间:2023-11-26 18:51:34
执行此操作的***方法是使用正则表达式匹配元音和辅音,然后打印每个元音和辅音。
The best way to do this is using regular expression to match vowels and consonants, and then print each of them.
下面是工作代码段:
Below is the working code snippet:
function vowelsAndConsonants(s) {
var vw =s.match(/[aeiouAEIOU]+?/g); //regular expression to match vowels
var con=s.match(/[^aeiouAEIOU]+?/g); //regular expression to not match vowels, ie. to match consonants
printOnConsole(vw); //print vowels
printOnConsole(con); //print consonants
}
//function to print values on console.
function printOnConsole(arrPrint){
for(var i=0;i<arrPrint.length;i++){
console.log(arrPrint[i]);
}
}