JS Built-ins
← Array114 / 226
ArrayArray.prototype.joinintermediate

Array.prototype.join() β€” build a file path

πŸ“– Usage Example
const parts = ['usr', 'local', 'bin']
parts.join('/')  // β†’ 'usr/local/bin'

Use join('/') to construct file paths from an array of path segments.

Array.prototype.join() β€” building paths

Joining path segments with '/' is a classic use case for join().

Challenge: Implement buildPath(parts) that joins path segments with '/'.

buildPath(['usr', 'local', 'bin']) // β†’ 'usr/local/bin'
buildPath(['src', 'index.ts'])     // β†’ 'src/index.ts'
πŸ’‘ Hints (2)
  • β€’ `join('/')` places a single `/` between each segment.
  • β€’ For absolute paths, prepend `/` to the result: `'/' + parts.join('/')`.