JSFiddle - React, Tailwind, and code Playground
by Josh Pullen
JavaScript
const syllables = str => str
.toLowerCase()
.split('')
.filter(c => /^[a-zA-Z ]$/.test(c))
.join('')
.split(' ')
.map(word => {
if (word.length <= 3) return 1
return word
.replace(/(?:[^laeiouy]es|ed|lle|[^laeiouy]e)$/, '')
.replace(/^y/, '')
.match(/[aeiouy]{1,2}/g)
.length
})
.reduce((sum, current) => sum + current, 0)
console.log(syllables('This is a test of analyzing text.'))