My one cent:

(defn count-vowels
  ([^String text]
    (count-vowels text "aeiouAEIOU"))
  ([^String text ^String accepted-vowels]
    (let [vowel? (set accepted-vowels)]
      (->> text
           (filter vowel?)
           count))))

user=> (count-vowels "Plínio Balduino")
6
user=> (count-vowels "Plínio Balduino" "aeiouAEIOUíÍ")
7

I think this solves the problems for US-ASCII vowels and specific locale
vowels.

Plínio


On Wed, May 21, 2014 at 4:35 AM, Vesa Marttila <vtmartt...@gmail.com> wrote:

> On Wednesday, May 21, 2014 2:03:14 AM UTC+3, Brad Kurtz wrote:
>>
>> I saw a rant online about interviewing developers that mentioned
>> candidates not being able to count the number of vowels in a string. So
>> naturally, I decided to see if I could do it in Clojure!
>>
>> I wanted to see others' opinions on other ways of doing it.
>>
>> *https://gist.github.com/bradkurtz/6ce500d0361ccdc08c8e
>> <https://gist.github.com/bradkurtz/6ce500d0361ccdc08c8e>*
>>
>
> Hi,
>
> I ended up with this: https://gist.github.com/ponzao/7399c08bb3b40d349289
>
>     (def vowels
>       #{\a \e \i \o \u})
>
>     (defn count-vowels
>       [s]
>
>       (count (keep vowels (.toLowerCase s))))
>
> Vesa
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to