Longest common suffix: Difference between revisions
Content deleted Content added
Line 1,585:
remark spark aardvark lark -> 'ark'
ectoplasm banana brick -> ''</pre>
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
This entry uses `longest_common_prefix` from [[Longest_common_suffix#jq]] and so the definition is not repeated here.
<lang jq>
# Input: an array of strings
def longest_common_suffix:
def r: explode | reverse | implode;
if length == 0 then "" # by convention
elif length == 1 then .[0] # for speed
else map(r)
| longest_common_prefix
| r
end;</lang>
'''Test Cases'''
<lang jq>def test:
["baabababc","baabc","bbbabc"],
["baabababc","baabc","bbbazc"],
[""],
[],
["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
["throne","cone", "bone"]
| "\(.) => \(longest_common_suffix)";
test
</lang>
{{out}}
<pre>
["baabababc","baabc","bbbabc"] => abc
["baabababc","baabc","bbbazc"] => c
[""] =>
[] =>
["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"] => day
["throne","cone","bone"] => one
</pre>
=={{header|Julia}}==
Line 1,602 ⟶ 1,639:
abc
c
</pre>
|