| 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 = [...path.matchAll(/\//g)].length |
| 6 | if (slashes < minSlashes) { |
| 7 | minSlashes = slashes |
| 8 | result = path |
| 9 | } |
| 10 | } |
| 11 | return result |
| 12 | } |
| 13 |