Count how many vowels and consonants occur in a string: Difference between revisions
Count how many vowels and consonants occur in a string (view source)
Revision as of 02:31, 21 December 2022
, 1 year agoAdded REBOL implementation
Jazzedpineda (talk | contribs) (Added REBOL implementation) |
|||
Line 1,939:
{{out}}
<pre>5 vowels and 8 consonants occur in the string "Forever Ring Programming Language"</pre>
=={{header|REBOL}}==
<syntaxhighlight lang="rebol">
REBOL [
Title: "Count how many vowels and consonants occur in a string"
Date: 21-Dec-2022
Author: "Earldridge Jazzed Pineda"
]
countVowelsConsonants: func [string] [
vowels: [#"a" #"e" #"i" #"o" #"u"]
consonants: [#"b" #"c" #"d" #"f" #"g" #"h" #"j" #"k" #"l" #"m" #"n" #"p" #"q" #"r" #"s" #"t" #"v" #"w" #"x" #"y" #"z"]
vowelCount: 0
consonantCount: 0
foreach character string [
if (find consonants character) <> none [consonantCount: consonantCount + 1]
if (find vowels character) <> none [vowelCount: vowelCount + 1]
]
return reduce [vowelCount consonantCount]
]
string: "Count how many vowels and consonants occur in a string"
counts: countVowelsConsonants string
print [mold string "has" pick counts 1 "vowels and" pick counts 2 "consonants"]
</syntaxhighlight>
{{out}}
<pre>{Count how many vowels and consonants occur in a string} has 15 vowels and 30 consonants</pre>
=={{header|REXX}}==
|