title: Javascript - Make object from another object through iteration/recursion
body: <p>The object I have is e.g.</p>
  
  <pre><code>[
      [
          ["first_name", "==", "tom"], "||", ["first_name", "==", "harry"]
      ], "&amp;&amp;", ["gender", "==", "m"]
  ]
  </code></pre>
  
  <p>The object I am trying to build from above is:</p>
  
  <pre><code>{
    "condition": "&amp;&amp;",
    "rules": [
      {
        "field": "gender",
        "operator": "==",
        "value": "m"
      },
      {
        "condition": "||",
        "rules": [
          {
           "field": "first_name",
            "operator": "==",
            "value": "tom"
          },
          {
            "field": "first_name",
            "operator": "==",
            "value": "harry"
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p><strong>What have I tried?</strong></p>
  
  <p>Well this feels so complicated right now that I cannot even come up with an initial concept. It seems to me that a recursive function call would be a good start. </p>
  
  <p><strong>What am I trying to achieve?</strong></p>
  
  <p>I have these rules inside an object and I want to convert them into <a href="http://querybuilder.js.org/demo.html" rel="nofollow noreferrer">Query Builder</a> rules.</p>
  
  <p>Can this be done with iteration/recursion and without actually using a lexer and parser? If so, then how would you do it? Browser JS solutions only please.</p>
  
  <p><strong>Please Note</strong></p>
  
  <p>The object can be n-level deep, so the solution has to be able to take that into account. </p>