给定字符串 str,检查其是否以元音字母结尾
1、元音字母包括 a,e,i,o,u,以及对应的大写
2、包含返回 true,否则返回 false
function endsWithVowel(str) { let l = str.slice(str.length-1); return /a|e|i|o|u/.test(l.toLowerCase()); }
function endsWithVowel(str) { return str && "aeiouAEIOU".includes(str[str.length-1], -1) }根据题意想到一个字符串内置方法 endsWith
function endsWithVowel(str) { for (let i = 0; i < 10; i++){ if (str.endsWith('aeiouAEIOU'[i])) { console.log('aeiouAEIOU'[i]) return true } } return false; }