| 1 | export function findShallowestPath(paths: Iterable<string>) { |
| 2 | let result: string | undefined |
| 3 | let minSlashes = Number.POSITIVE_INFINITY |
| 4 | for (const path of paths) { |
| 5 | const slashes = [ |
| 6 | ...path.matchAll(/\//g), |
| 7 | ].length |
| 8 | if (slashes < minSlashes) { |
| 9 | minSlashes = slashes |
| 10 | result = path |
| 11 | } |
| 12 | } |
| 13 | return result |
| 14 | } |
| 15 |