Here's mine... would have liked to use String.prototype.matchAll, but my JS engine didn't support it. So used a generator and Array.from instead. :-)
function*matchAll(str,re){letmatch;do{match=re.exec(str);// get the first match of the regular expessionif(match)yieldmatch;// if we have one, yield it}while(match!=null);// keep going until no more matches}constgetLongestSequence=(str,re)=>Array.from(matchAll(str,re))// generators are iterable.map(([seq])=>seq)// extract the string from the regex match result.reduce((longest,cur)=>cur.length>longest.length?cur:longest// keep track of longest,"");constgetLongestVowelSequence=str=>getLongestSequence(str,/[aeiou]+/gi);// use vowels -- g = global; i = case insensitive
Here's mine... would have liked to use
String.prototype.matchAll
, but my JS engine didn't support it. So used a generator andArray.from
instead. :-)Full Gist: gist.github.com/kerrishotts/a3ec30...
Just noticed that the challenge is to return the length ;-) Oh well --
getLongestVowelSequence("codewarriors").length
will do ;-)