EasyPythonJavaScriptTypeScript

path.join

Node.jsPathsStrings

Join URL/POSIX path segments with / and normalize:

  • Collapse multiple slashes.
  • Drop empty segments (except a leading absolute marker).
  • Preserve a leading / if the first segment starts with one.

solve(['/a', 'b', '/c/'])'/a/b/c/' (preserves trailing slash of last segment).

Sample tests

Test #1Relative
Input: [["a","b"]]
Output: "a/b"
Test #2Absolute three segments
Input: [["/a","b","c"]]
Output: "/a/b/c"
Test #3Just root
Input: [["/"]]
Output: "/"
Test #4Empty segment dropped
Input: [["a","","b"]]
Output: "a/b"
Test #5Trailing slash preserved
Input: [["/a","b","/c/"]]
Output: "/a/b/c/"