Jump to content

Longest common suffix: Difference between revisions

Added BaCon version.
m (→‎AppleScript :: Functional: Tidier test format.)
(Added BaCon version.)
Line 480:
['remark', 'spark', 'aardvark', 'lark'] -> 'ark'
['ectoplasm', 'banana', 'brick'] -> ''</pre>
 
=={{header|Delphi}}==
<lang BaCon>FUNCTION Common_Suffix$(data$)
 
LOCAL x, size
LOCAL delim$
 
REPEAT
delim$ = ""
INCR size
 
FOR x = 1 TO AMOUNT(data$)
delim$ = APPEND$(delim$, 0, RIGHT$(TOKEN$(data$, x), size))
NEXT
UNTIL AMOUNT(UNIQ$(delim$)) <> 1
 
RETURN RIGHT$(TOKEN$(data$, 1), size-1)
 
ENDFUNCTION
 
PRINT "The common suffix is: '", Common_Suffix$("baabababc baabc bbbabc"), "'"
PRINT "The common suffix is: '", Common_Suffix$("Monday Tuesday Wednesday Thursday Friday Saturday Sunday"), "'"
PRINT "The common suffix is: '", Common_Suffix$("longest common suffix"), "'"
PRINT "The common suffix is: '", Common_Suffix$("prefix suffix"), "'"
PRINT "The common suffix is: '", Common_Suffix$(""), "'"</lang>
{{out}}
<pre>The common suffix is: 'abc'
The common suffix is: 'day'
The common suffix is: ''
The common suffix is: 'fix'
The common suffix is: ''</pre>
 
 
=={{header|Delphi}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.