Find common directory path: Difference between revisions

→‎{{header|PowerShell}}: add version that leverage Powershell Cmdlet
(Added Elixir)
(→‎{{header|PowerShell}}: add version that leverage Powershell Cmdlet)
Line 1,387:
Output:
<lang>The common directory path is /home/user1/tmp</lang>
 
 
Another version that leverage cmdlet in Powershell
 
<lang Powershell>
Function Get-CommonPath( $PathList ){
$Directories = $PathList | foreach { ,(Split-String -Input $_ -Separator '/') }
$MinDirectoryDepth = $Directories | Measure-Object -Property Length -Minimum | Select -ExpandProperty Minimum
$CommonPath = foreach ($Index in 0..($MinDirectoryDepth - 1)) {
$UniquePath = @($SplitPaths | foreach { $_[$Index] } | Sort -Unique)
if ($UniquePath.Length -gt 1) {
break;
}
 
$UniquePath
}
 
$CommonPath | Join-String -Separator '/'
}
</lang>
 
with the following sample execution:
<lang>
PS> Get-CommonPath "/home/user1/tmp/coverage/test","/home/user1/tmp/covert/operator","/home/user1/tmp/coven/members"
/home/user1/tmp
</lang>
 
=={{header|PureBasic}}==
Anonymous user