main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function calcAvgHeight(data) {
  // Calculate average height from received data. If no data, return null.
  
  if (data) {
    
   var heights = [];

    Object.keys(data).forEach(function(person) {
      var p = data[person];
      heights.push(p.height);
    });
    
    var sum = 0;
    
    heights.forEach(function(e){
      sum += e;
    });
    
    avg = sum / heights.length;
    
    return avg;
    
  } else {
    return null;
  }
  

  
}

var avgHeight = calcAvgHeight({
  Matt: { height: 174, weight: 69 },
  Jason: { height: 190, weight: 103 }
});
console.log(avgHeight);
Native Browser JavaScript