Directory calculation For this challenge, you will be given an absolute path, and a &quot;new&quot; path (which can be absolute or relative), and you need to return the final path.
For example, if your current directory was /var/tmp/test:
my_dir or my_dir/  should return /var/tmp/test/my_dir
../../my_dir should return /var/my_dir
/my_dir/./ should return /my_dir
../../../../../ should return /
To be more pedantic:

A directory is a non-empty string consisting of alphanumeric characters and the symbols -,_, or .
A path is a list of 0 or more directories, separated using /.  An absolute path starts with a /, a relative path does not.  Paths can include an ending /.

You need to &quot;resolve&quot; the second path, given the first path.
The process of resolving is:

Test if the second path is relative.  If so, then insert the absolute path's directories to the beginning of the second path.
If any of the directories is .., then remove it and the preceding directory.  If it is the first directory, then simply remove it.
If any of the directories is ., then remove it.
Output the final absolute path.  You should not output an ending /.

You do not need to handle incorrect input.  The commands should work, whether or not the directories passed actually exist on your machine.  You can assume that everything is a directory, even if it has an extension.
Test cases
Absolute      New          Output
&quot;/a/b/c&quot;      &quot;d&quot;       -&gt; &quot;/a/b/c/d&quot; 
&quot;/a/b/c/&quot;     &quot;d&quot;       -&gt; &quot;/a/b/c/d&quot;
&quot;/a/b/c/&quot;     &quot;d/&quot;      -&gt; &quot;/a/b/c/d&quot;
&quot;/a/b/c&quot;      &quot;/d&quot;      -&gt; &quot;/d&quot;
&quot;/a/b/c&quot;      &quot;/d/&quot;     -&gt; &quot;/d&quot;
&quot;/../a/b/c/&quot;  &quot;d&quot;       -&gt; &quot;/a/b/c/d&quot;
&quot;/a/../b/c/&quot;  &quot;d&quot;       -&gt; &quot;/b/c/d&quot;
&quot;/a/b/../c&quot;   &quot;d&quot;       -&gt; &quot;/a/c/d&quot;
&quot;/a/b/c/..&quot;   &quot;d&quot;       -&gt; &quot;/a/b/d&quot;
&quot;/a/b/c/&quot;     &quot;..&quot;      -&gt; &quot;/a/b&quot;
&quot;/a/b/c&quot;      &quot;../d&quot;    -&gt; &quot;/a/b/d&quot;
&quot;/a/b/c&quot;      &quot;/../d&quot;   -&gt; &quot;/d&quot;
&quot;/a/b/c&quot;      &quot;&quot;        -&gt; &quot;/a/b/c&quot;
&quot;/a/b/c&quot;      &quot;.&quot;       -&gt; &quot;/a/b/c&quot;
&quot;/a/b/c&quot;      &quot;./d&quot;     -&gt; &quot;/a/b/c/d&quot;
&quot;/a/b/c&quot;      &quot;/./d&quot;    -&gt; &quot;/d&quot;
&quot;/a/b/c&quot;      &quot;d.txt&quot;   -&gt; &quot;/a/b/c/d.txt&quot;
&quot;/a/b/c&quot;      &quot;d.&quot;      -&gt; &quot;/a/b/c/d.&quot;
&quot;/a/b/c&quot;      &quot;.txt&quot;    -&gt; &quot;/a/b/c/.txt&quot;
&quot;/a/b/c&quot;      &quot;.txt/d&quot;  -&gt; &quot;/a/b/c/.txt/d&quot;
&quot;/a/b/.&quot;      &quot;./././.&quot; -&gt; &quot;/a/b&quot;
&quot;/direc&quot;      &quot;tory&quot;    -&gt; &quot;/direc/tory&quot;
&quot;/a-_.b/&quot;     &quot;__._-.&quot;  -&gt; &quot;/a-_.b/__._-.&quot;
&quot;/a/b&quot;        &quot;../..&quot;   -&gt; &quot;/&quot;
&quot;/a/b&quot;        &quot;../../..&quot;-&gt; &quot;/&quot;
&quot;/a&quot;          &quot;../../..&quot;-&gt; &quot;/&quot;
&quot;/&quot;           &quot;&quot;        -&gt; &quot;/&quot;
&quot;/&quot;           &quot;a&quot;       -&gt; &quot;/a&quot;
&quot;/..&quot;         &quot;a&quot;       -&gt; &quot;/a&quot;
&quot;/.&quot;          &quot;&quot;        -&gt; &quot;/&quot;

This is a code-golf, so make your submissions as short as possible in your favorite language!
Retina, 44 bytes

+`.+ /| |/\.?/
/
+1`/?[^/]*/\.\.|/\.?$

^$
/


Input is expected to be the two paths separated by a single space.

Try it online! (The first line enables a linefeed-separated test suite.)