I came up with two that take their values from STDIN which are based on the Perl 5 answer.
lines~~/(.*).*' '$0/;say ~$0
lines~~/:s(.*).* $0/;say ~$0
The first requires exactly one space between the inputs, while the other requires at least one whitespace character between the inputs.
That is quite a bit shorter than the first thing I tried which takes the values from the command line.
say [~] map ->($a,$b){$a eq$b&&$a||last},[Z] @*ARGS».comb # 58 bytes
or even the lambda version of it:
{[~] map ->($a,$b){$a eq$b&&$a||last},[Z] @_».comb} # 52 bytes
Though this is much easier to adjust so that it accepts any number of input strings, at the cost of only one stroke.
{[~] map ->@b {([eq] @b)&&@b[0]||last},[Z] @_».comb} # 53 bytes
# ┗━┛ ┗━━━━━━━┛ ┗━━━┛
my &common-prefix = {[~] map ->@b {([eq] @b)&&@b[0]||last},[Z] @_».comb}
say common-prefix <department depart>; # "depart"
say common-prefix; # ""
say common-prefix <department depart depot deprecated dependant>; # "dep"
# This code does not work directly with a single argument, so you have
# to give it an itemized List or Array, containing a single element.
say common-prefix $('department',); # "department"
# another option would be to replace `@_` with `(@_,)`
"aca", "aba"
입니다.