title: How to return the average of values in different objects with the same key value in an array on JS?
body: <p>Imagine I have an array:</p>
  <pre><code>let profile = [
  {student: &quot;A&quot;, english: 80, maths: 80},
  {student: &quot;A&quot;, english: 70, maths: 60},
  {student: &quot;B&quot;, english: 50, maths: 50},
  {student: &quot;B&quot;, english: &quot;--&quot;, maths: 60},
  ...
  ]
  </code></pre>
  <p>I want to get two sets of array regarding the average.</p>
  <ol>
  <li>The average scores of each subject of each student (Expected output:)</li>
  </ol>
  <pre><code>[{student: &quot;A&quot;, english: 75, maths: 70},
  {student: &quot;B&quot;, english: 50, maths: 55}]
  </code></pre>
  <ol start="2">
  <li>The average scores of every subject of each student (Expected output:)</li>
  </ol>
  <pre><code>[{student: &quot;A&quot;, average: 72.5},
  {student: &quot;B&quot;, average: 53.3}]
  </code></pre>
  <p>How can I code it? Thank you very much</p>