title: Lodash: Constructing single object from many - Merging/overriding properties
body: <blockquote>
    <p>Note: I filed this question under lodash as I'm pretty sure it can help me solve that problem nicely, but haven't put my finger on it just now</p>
  </blockquote>
  
  <p>I have an object describing different user roles and their permissions;</p>
  
  <p>I will have something like 10-15 roles defined "like this" (<em>this doesn't reflect the application code but the problem itself</em>):</p>
  
  <pre><code>    var role1 = {
      views: {
          v1: {access: true},
          v2: {access: false},
          v#: {access: false}
      }
  }
  
  var role2 = {
      views: {
          v1: {access: false},
          v2: {access: true},
          v3: {access: true},
      }
  }
  </code></pre>
  
  <p>The user connected will have multiple roles; In that example it could be <code>['role1', 'role2']</code>, and out of this I need to construct a single <code>permissions</code> object that will be a combination of all the props defined in all the user roles.</p>
  
  <p>It is basically whitelist-based, where all "true" properties should override anything that was defined as false. Thus, the expected result should be:</p>
  
  <pre><code>permissions = {
      views: {
          v1: {access: true},
          v2: {access: true},
          v2: {access: true}
      }
  }
  </code></pre>
  
  <hr>
  
  <p>I'm not too sure how to tackle that one without relying on crazy nested loops</p>
  
  <p>Here's a starting point in JSBin: <a href="http://jsbin.com/usaQejOJ/1/edit?js,console">http://jsbin.com/usaQejOJ/1/edit?js,console</a></p>
  
  <p>Thanks for your help!</p>