title: Create nested object of booleans, arrays and objects from array
body: <p>I am trying to create an object to satisfy the structure required by <a href="https://jsonlogic.com/" rel="nofollow noreferrer">json-logic-js</a>. An example of that structure is provided below.</p>
  <p>The source array is made up of <code>booleans</code> and <code>strings</code>. Strings can only be <code>OR</code>, <code>AND</code>, <code>NAND</code> or <code>NOR</code>. For now am I working only with <code>OR</code> and <code>AND</code>.</p>
  <p>The array of booleans and strings might look like the below. The values are dynamic. So the booleans can be either true or false and strings as mentioned above.</p>
  <pre><code>const source = [false, &quot;OR&quot;, false, &quot;OR&quot;, false, &quot;AND&quot;, false, &quot;AND&quot;, false, &quot;OR&quot;, true]
  </code></pre>
  <p>The grouping of this source array if it were in an if statement would I believe be as follows:</p>
  <pre><code>(false || false || (false &amp;&amp; false &amp;&amp; false) || true) // true
  </code></pre>
  <p>And I would expect to output the following object which satifies the json-logic-js JS package:</p>
  <pre><code>const result = {
      'or': [
          false,
          false,
          {
              'and': [
                  false,
                  false,
                  false,
              ]
          },
          true,
      ]
  }
  </code></pre>
  <p>I have tried recursive functions and have been playing with the .reduce() method but as have yet been unable to find a solution. I struggle creating the object as I iterate over the source array. I have searched for similar answers here on SO but none seem to want the same result object structure as I do.</p>