Count how many vowels and consonants occur in a string: Difference between revisions
Content added Content deleted
m (→JS :: Count of "Vowels and Consonants" ?: Preferred Array.from to String.split) |
|||
Line 807: | Line 807: | ||
Consonants: 31 (distinct 13) |
Consonants: 31 (distinct 13) |
||
</pre> |
</pre> |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
|||
<lang Mathematica>vowels = {"a", "e", "i", "o", "u"}; |
|||
conso = {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"}; |
|||
vowels = Join[vowels, ToUpperCase@vowels]; |
|||
conso = Join[conso, ToUpperCase@conso]; |
|||
str = "The universe is under no obligation to make sense to you."; |
|||
<|"vowels" -> StringCount[str, Alternatives @@ vowels], |
|||
"consonants" -> StringCount[str, Alternatives @@ conso], |
|||
"other" -> StringCount[str, Except[Alternatives @@ Join[vowels, conso]]]|></lang> |
|||
{{out}} |
|||
<pre><|"vowels" -> 22, "consonants" -> 24, "other" -> 11|></pre> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |