re: Daily Challenge #80 - Longest Vowel Change VIEW POST

FULL DISCUSSION
 

Javascript with reduce

const word = "codewarriors"

function findLongestVowels(word) {
  const regex = /[aeiou]/;

  const vowels = Array.prototype.reduce.call(word, 
      (currentLetters, nextLetter, index) => {
       if (regex.test(nextLetter)) {
           return regex.test(word[index-1]) ? 
                    currentLetters.concat('', nextLetter) : 
                    currentLetters.concat(' ', nextLetter);
       } else {
           return currentLetters;
       }
   }, "");

  const longestVowels = vowels.split(' ').reduce( (longest, current) => {
       return current.length > longest.length ? current : longest;
  }, "");

  return longestVowels.length;
}

console.log("Length of the longest vowel: " + findLongestVowels(word));
code of conduct - report abuse