使用 JavaScript 查找字符串中最长的元音子字符串
问题
我们要求编写一个接受字符串的 JavaScript 函数。该函数应返回仅包含元音的最长连续子字符串的长度。
示例
以下为代码 −
const str = 'schooeal';
const findLongestVowel = (str = '') => {
let cur = 0
let max = 0
for (let i = 0; i < str.length; ++i) {
if ("aeiou".includes(str[i])) {
cur++
if (cur > max) {
max = cur
}
} else {
cur = 0
}
}
return max
};
console.log(findLongestVowel(str));输出
4
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP