Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/package/src/common/import-report/utils.ts
6451 views
1
// https://stackoverflow.com/a/68702966
2
export const longestCommonDirPrefix = (strs: string[]) => {
3
if (strs.length === 0) return "";
4
let prefix = strs.reduce((acc, str) => str.length < acc.length ? str : acc);
5
6
for (const str of strs) {
7
while (str.slice(0, prefix.length) != prefix) {
8
prefix = prefix.slice(0, -1);
9
}
10
}
11
prefix = prefix.slice(0, prefix.lastIndexOf("/") + 1);
12
return prefix;
13
};
14
15