Skip to content

Instantly share code, notes, and snippets.

@thiegomoura
Last active June 28, 2023 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiegomoura/d760e4cd5b7e6d33d890df1091087751 to your computer and use it in GitHub Desktop.
Save thiegomoura/d760e4cd5b7e6d33d890df1091087751 to your computer and use it in GitHub Desktop.
Vowel count with async function
const vowels = ["a", "e", "i", "o", "u"]
function vowelCount(text, callback) {
const letters = text.split('')
const vowelCount = letters.reduce((acc, value) => {
const isVowel = vowels.includes(value.toLowerCase())
if (isVowel) acc++
return acc
}, 0)
return callback(vowelCount)
}
function print(value) {
console.log('result: ', value)
}
vowelCount('thiego', print)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment