Count how many vowels and consonants occur in a string: Difference between revisions

Content added Content deleted
(Applesoft BASIC)
(J)
Line 856: Line 856:
('t',1)
('t',1)
('v',1)</pre>
('v',1)</pre>

=={{header|J}}==

For this task, we restrict ourselves to english letters, and treat the semivowels (<code>w</code> and <code>y</code>) as consonants.

Implementation (two tallies: vowels first, consonants second):

<lang j>vowel=: (,toupper) 'aeiou'
consonant=: (,toupper) (a.{~97+i.16) -. vowel
vctally=: e.&vowel ,&(+/) e.&consonant</lang>

Examples:

<lang J> vctally 'Now is the time for all good men to come to the aid of their country.'
22 18
vctally 'Forever Action! programming language'
13 13</lang>


=={{header|JavaScript}}==
=={{header|JavaScript}}==