Saturday, March 14, 2009

Soundex

This week we're going to write a function to convert letters to their corresponding soundex codes. But wait, there's more! We'll also allow you to pass in an entire string and convert the whole thing. Here's the set up:


  1. function soundex(someString)
  2.     if len(someString) = 1 then
  3.         ' code to convert a single character
  4.     else
  5.         ' loop through the whole string and convert each character
  6.     end if
  7. end function

Inside the loop, we'll recursively call the soundex function to convert the individual character. Actually, this may not perfectly fit the definition of recursion. The only recursive aspect of it is that the function calls itself, but an entirely different execution path is being followed once inside. But that's good, because we won't have the poor performance that sometimes comes with recursion.


Once again, the full source code is a little too long to post, so you'll have to grab it from Snipplr:


No comments: