Advertisement
MiroJoseph

Vowel Count

Apr 4th, 2020
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.53 KB | None | 0 0
  1. My:
  2. object Sol {
  3.  
  4.   def getCount(inputStr: String, counter:Int=0): Int = {
  5.   if (counter<inputStr.length())
  6.     inputStr(counter) match{
  7.     case 'a'=>getCount(inputStr,counter+1)+1
  8.     case 'e'=>getCount(inputStr,counter+1)+1
  9.     case 'i'=>getCount(inputStr,counter+1)+1
  10.     case 'o'=>getCount(inputStr,counter+1)+1
  11.     case 'u'=>getCount(inputStr,counter+1)+1
  12.     case _ =>getCount(inputStr,counter+1)
  13.     }
  14.     else 0
  15.   }
  16. }
  17.  
  18. Other:
  19. object Sol {
  20.  
  21.   def getCount(s: String): Int = {
  22.     s.count("aeiou".contains(_))
  23.   }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement