MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / nearest

Function nearest

src/resolution/pascal-scope.ts:1065–1080  ·  view source on GitHub ↗

The file whose path shares the longest directory prefix with `from`.

(files: string[], from: string)

Source from the content-addressed store, hash-verified

1063
1064/** The file whose path shares the longest directory prefix with `from`. */
1065function nearest(files: string[], from: string): string | null {
1066 if (files.length <= 1) return files[0] ?? null;
1067 const dirs = from.split('/');
1068 let best: string | null = null;
1069 let bestScore = -1;
1070 for (const f of files) {
1071 const parts = f.split('/');
1072 let score = 0;
1073 while (score < parts.length && score < dirs.length && parts[score] === dirs[score]) score++;
1074 if (score > bestScore) {
1075 best = f;
1076 bestScore = score;
1077 }
1078 }
1079 return best;
1080}
1081
1082// ---------------------------------------------------------------------------
1083// Declared types

Callers 2

includesOfFunction · 0.85
unitFileNamedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected