title: JS update nested object with array changes
body: <p>Hi i need some help to update the userSettings variable, for example if i remove a product of the products array, i need to update the sortedProducts array of the userSettings.categories array, i'm trying with nested for loops but i would like to improve performance with functional array methods. This is what i've been trying, thanks in advance community.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let products = [
          {id: 1, name: 'Brasilian', category: 'cofee'},
          {id: 2, name: 'Colombian', category: 'cofee'},
          {id: 3, name: 'Apple', category: 'fruit'},
          {id: 4, name: 'Strawberry', category: 'fruit'},
          {id: 5, name: 'Banana', category: 'fruit'},
          {id: 6, name: 'Pepper', category: 'spices'},
          {id: 7, name: 'Salt', category: 'spices'}
      ]
      
  let userSettings = {
      categories: [
          {name: 'fruit', sortedProducts: [5, 3, 4]},
          {name: 'spices', sortedProducts: []},
          {name: 'cofee', sortedProducts: []},
      ]
  }
  
  // lets remove the strawberry product
  products.splice(3, 1);
  console.log(products);
  
  
  // i need to update userSettings
  const updateUserSettings = (() =&gt; {
  
      for(let i = 0; i &lt; userSettings.categories.length; i++){
  
          if(userSettings.categories[i].sortedProducts.length){
              console.log(userSettings.categories[i].sortedProducts);
  
              for(let j = 0; j &lt; products.length; j++){
                  if(products[j].category == userSettings.categories[i] &amp;&amp; !userSettings.categories[i].sortedProducts.includes(products[j].id)){
                      console.log('no includes')
                  }
              }
        
          }
      }
  
  })();
  
  
  
  
  
  
  expectedOutput = {
      categories: [
          {name: 'fruit', sortedProducts: [5, 3]},
          {name: 'spices', sortedProducts: []},
          {name: 'cofee', sortedProducts: []},
      ]
  }</code></pre>
  </div>
  </div>
  </p>