RosettaCodeData/Task/Find-common-directory-path/Mathematica/find-common-directory-path.math
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

5 lines
304 B
Text

FindCommonDirectory[x_] := If[StringTake[#, -1] != "/", StringTake[#, Max[StringPosition[#, "/"]]], #] &
[Fold[LongestCommonSubsequence, First[x] , Rest[x]]]
FindCommonDirectory[{"/home/user1/tmp/coverage/test", "/home/user1/tmp/covert/operator", "/home/user1/tmp/coven/members"}]
->"/home/user1/tmp/"