October 2013
Intermediate to advanced
368 pages
9h 20m
English
What about vowels? Rule #3 also states that otherwise-duplicate encodings separated by a vowel (not h or w) get coded twice.
| c2/39/SoundexTest.cpp | |
| | TEST_F(SoundexEncoding, DoesNotCombineDuplicateEncodingsSeparatedByVowels) { |
| | ASSERT_THAT(soundex.encode("Jbob"), Eq("J110")); |
| | } |
Once again we solve our challenge by declaring what we want to accomplish. We change the conditional expression in
encodeLetter
to append a digit only if it is not a duplicate or if the last letter is a vowel. This declaration drives a few corresponding changes.
| c2/39/Soundex.h | |
| | void encodeTail(std::string& encoding, const std::string& word) const { |
| * | for (auto i = 1u; i < word.length(); i++) |
| * | if (!isComplete(encoding)) ... |