CoffeeScript function: Counts the number of vowels within a string
CoffeeScript Function : Exercise-14 with Solution
Write a CoffeeScript function that accepts a string as a parameter and counts the number of vowels within the string.
Note : As the letter 'y' can be regarded as both a vowel and a consonant, we do not count 'y' as a vowel here.
Example string : 'The quick brown fox'
Expected Output : 5
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script> <title>Counts the number of vowels within a string </title> </head> <body> </body> </html>
vowel_count = (str1) -> vowel_list = 'aeiouAEIOU' vcount = 0 x = 0 while x < str1.length if vowel_list.indexOf(str1[x]) != -1 vcount += 1 x++ vcountconsole.log vowel_count('The quick brown fox')
Improve this sample solution and post your code through Disqus.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join