Recursively extract contents of (nested) parentheses in string
<p>I'm trying to write a function that extracts the words contained in parentheses into their own array, recursively to account for nested parentheses.</p>

<p>So for "((a b) ugh (one two)) pi", i'd like that to translate to the following structure:</p>

<pre><code>[
  [
    [
      "a",
      "b"
    ],
    "ugh",
    [
      "1",
      "2"
    ],
  ]
  "pi"
]
</code></pre>

<p>To that end, I've written the following function:</p>

<pre><code>function shitshow(hell) {
    var ssparts = [];
    var done = false;
    for (i in hell) {
        let part = hell[i];
        switch(part) {
            case "(":
                ssparts.push(shitshow(hell.slice(i+1)));
                break;
            case ")":
                done = true;
                break;
            default:
                ssparts.push(part);
        }
        if (done) break;
    }
    return ssparts;
}

console.log(shitshow("((developer or engineer) or (nurse or doctor)) and manager"));
</code></pre>

<p>It doesn't work. The array it returns for me (I'm testing this on Node 4):</p>

<pre><code>[
  "",
  [
    "doctor"
  ],
  [],
  "developer",
  "or",
  "engineer"
]
</code></pre>

<p>Been wrestling with this for a while. Any ideas?</p>

<hr>

<p>EDIT: As @Oriol mentioned below in this post's comments, my posted code does not produce my posted output. This is because I forgot to mention/include where I RegEx'd the initial string into an array of words and non-alphanumeric symbols. Sorry about this. Because @Oriol has already posted a working solution, I am including this notice instead of updating my code, so that his posted solution can stand.</p>