Vowel families
Given two words, we can determine if they have the same vowels, ignoring order and repetition. For instance, "Hello" and "Vowel" both have \e
and \o
, so they have the same vowels. Write a function that groups words into "families" that all have the same vowels. "Tree" and "tent" also belong to the same family because we ignore the repetition of \e
.
Examples
(vowel-families ["hello" "vowel" "fox" "cot" "hat" "cat"]) ;=> [["hello" "vowel"]
; ["fox" "cot"]
; ["hat" "cat"]]
(vowel-families []) ;=> []
(vowel-families ["tree" "tent" "blanket"] ;=> [["tree" "tent"]
; ["blanket"]]
Notes
For this exercise, the vowels are \a
, \e
, \i
, \o
, and \u
. If you wish, you may include vowels from other languages and scripts.
Your algorithm should not be case-sensitive.
Please maintain capitalization and non-alphabetic characters.
Thanks to this site for the problem idea, where it is rated Very Hard in Python. The problem has been modified.
Please submit your solutions as comments on this gist.
To subscribe: https://purelyfunctional.tv/newsletter/
Edit: I don't usually write clojure, but I noticed the other submissions have the branch to check for an empty vector. Apparently
vals
returnsnil
for an empty map instead of returning an empty sequence. Is there a reason for this? I'm just curious.My fix for my code would be to wrap it with
(or ... [])
: