Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var data = [
  [1, 2, 3, 4, 5, 6],
  [10, 20, 30, 40, 50, 60]
];
//create the same nummber of empty arrays as there are arrays in data.
var averagedCols = new Array(data.length).fill([]);
for (var i = 0; i < data.length; i++) {
  for(var j = 0; j < data[i].length; j++) {
    if (j%2 === 0) {
      var average = (data[i][j] + data[i][j+1])/2;
      averagedCols[i].push(average);
    } 
  }
}
console.log(averagedCols);
//expecting [1.5, 3.5, 5.5]
console.log(averagedCols[0]);
//expecting [15, 35, 55]
console.log(averagedCols[1]);
Output 300px

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers