RosettaCodeData/Task/Find-common-directory-path/Lingo/find-common-directory-path-1.lingo
2023-07-01 13:44:08 -04:00

19 lines
508 B
Text

on getCommonPath (pathes, sep)
_player.itemDelimiter = sep
-- find length of shortest path (in terms of items)
commonCnt = the maxInteger
repeat with p in pathes
if p.item.count<commonCnt then commonCnt=p.item.count
end repeat
pathCnt = pathes.count
repeat with i = 1 to commonCnt
repeat with j = 2 to pathCnt
if pathes[j].item[i]<>pathes[j-1].item[i] then
return pathes[1].item[1..i-1]
end if
end repeat
end repeat
return pathes[1].item[1..commonCnt]
end