PHP Data structures Strings Public



Write a function that provides change directory (cd) function for an abstract file system.


  • Root path is '/'.
  • Path separator is '/'.
  • Parent directory is addressable as '..'.
  • Directory names consist only of English alphabet letters (A-Z and a-z).
  • The function will not be passed any invalid paths.
  • Do not use built-in path-related functions.

For example:

$path = new Path('/a/b/c/d');
echo $path->cd('../x')->currentPath;

should display '/a/b/c/x'.

PHP 7.1.9

  •   Example case: Wrong answer
  •   Two times down: Wrong answer
  •   Three times up: Wrong answer
  •   Complex paths: Wrong answer