title: find max and min in reduce function javascript
body: <p>how to find max and min value inside reduce function.I can do sum of 'a' and sum of 'b' in the data set  but I can't find the maximum a and the minumum b and add it in the same list</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>var liste = [
    {"id":1,"a":5,"b":4},
    {"id":1,"a":2,"b":2},
    {"id":1,"a":7,"b":1},
    {"id":1,"a":1,"b":0},
    
    {"id":2,"a":11,"b":5},
    {"id":2,"a":32,"b":75},
    {"id":3,"a":1,"b":1},
    {"id":4,"a":1,"b":1},
    {"id":4,"a":213,"b":1},
    {"id":5,"a":1,"b":1},
    {"id":5,"a":1,"b":1},
  ]
  var max = 0;
  let map = liste.reduce((prev, next) =&gt; {  
    
      if (next.id in prev) {
         prev[next.id].a += next.a;
         prev[next.id].b += next.b;
         if(next.a &gt; max){
           max = next.a;
           prev[next.id].max = max;
           
         }
      } else {
         prev[next.id] = next;
        
         next.max =max
      }
      return prev;
  }, {});
  let result = Object.keys(map).map(id =&gt; map[id]);
  console.log(result);</code></pre>
  </div>
  </div>
  </p>