recursive function -
12-06-2005
, 09:58 AM
I'm trying to figure out what I have missed in the following:
I want to compare two names on an 'editCompare' function. Meaning that if I
compared
Ursus against Ursus the func would yield 0
Uksus against Urkus would yield 1 (only one letter different)
Usus would yield 4 (only the first u matches)
Ursus against MyFirstName would result in 10 since no letters matched the 10
letters of MyFirstname
I have written a complex function that does the job, but wanted to replace
it by a much neater recurring function
test ( name1 ; name2 ; 0 )
Let ( [
result = Case ( Length ( name1 & name2 ) > 0 ; //As long as both names
contain any characters keep looping
If ( Left ( name1; 1 ) = Left ( name2 ; 1) ; result ; result + 1 ) ;
//Compare the first letter of each name, when no match result keeps the
same, otherwise result+1
test ( Right ( name1 ; Length ( name1 ) -1 ) ; Right ( name2 ; Length (
name2 ) -1 ) ; result ) ; //Recall the test with new parameters (name minus
first letter and new result)
result ) ] ;
result )
I must have mist something since it only returnes the same value all the
time. And ofcourse does my old solution still works, but I'm pretty sure
someting like the new solution should work, and neater.
--
Keep Well,
Ursus |