Jump to content

Longest common suffix: Difference between revisions

Added AutoHotkey
(Added AutoHotkey)
Line 480:
['remark', 'spark', 'aardvark', 'lark'] -> 'ark'
['ectoplasm', 'banana', 'brick'] -> ''</pre>
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>Longest_common_suffix(data){
for num, v in StrSplit(data.1)
for i, word in data
if (SubStr(word, 1-num) <> SubStr(data.1, 1-num))
return num=1 ? "-" : SubStr(word, 2-num)
return word
}</lang>
Examples:<lang AutoHotkey>MsgBox % ""
. "`n" Longest_common_suffix(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"])
. "`n" Longest_common_suffix(["throne", "throne"])
. "`n" Longest_common_suffix(["throne", "dungeon"])
. "`n" Longest_common_suffix(["throne", "", "throne"])
. "`n" Longest_common_suffix(["cheese"])
. "`n" Longest_common_suffix([""])
. "`n" Longest_common_suffix(["prefix", "suffix"])
. "`n" Longest_common_suffix(["send", "lend"])
return</lang>
{{out}}
<pre>day
throne
-
-
cheese
 
fix
end
</pre>
 
=={{header|BaCon}}==
299

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.