Count how many vowels and consonants occur in a string: Difference between revisions
Content deleted Content added
Realize in F# |
→{{header|Ruby}}: Add Ruby |
||
Line 498: | Line 498: | ||
</pre> |
</pre> |
||
=={{header|Ruby}}== |
|||
<lang ruby>RE_V = /[aeiou]/ |
|||
RE_C = /[bcdfghjklmnpqrstvwxyz]/ |
|||
str = "Now is the time for all good men to come to the aid of their country." |
|||
grouped = str.downcase.chars.group_by do |c| |
|||
case c |
|||
when RE_V then :Vowels |
|||
when RE_C then :Consonants |
|||
else :Other |
|||
end |
|||
end |
|||
grouped.each{|k,v| puts "#{k}: #{v.size}, #{v.uniq.size} unique."} |
|||
</lang> |
|||
{{out}} |
|||
<pre>Consonants: 31, 13 unique. |
|||
Vowels: 22, 5 unique. |
|||
Other: 16, 2 unique. |
|||
</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-str}} |
{{libheader|Wren-str}} |