for loops iterating and printing sub-array averages

PHOTO EMBED

Fri Apr 07 2023 17:32:13 GMT+0000 (Coordinated Universal Time)

Saved by @thecowsays #javascript

let temperature_data = [
  [60.2, 61.2, 63.4, 64.8, 65.1, 63.2, 62.9],
  [62.5, 63.8, 63.4, 64.6, 65.8, 64.9, 65.0],
  [63.4, 64.5, 65.2, 64.8, 65.1, 64.9, 66.2],
  [66.3, 66.8, 66.4, 66.8, 67.8, 67.9, 68.2]
];
for (i = 0; i < 4; i++) {
  let length = temperature_data[i].length;
  let weeklySum = 0;
  for (j = 0; j < length; j++) {
    weeklySum += temperature_data[i][j];
  }
  console.log("Week " + i + " Average Temperature: " + (weeklySum / 7));
}
content_copyCOPY

the first loop iterates through each subarray; second loop averages each sub-array. output is the average for each week's temperature