So in my google sheet i have some data: in column A i have dates in column B i have numbers

also i have 2 cells with starting date and end date which i use to filter array.

What i need to get the sum of filtered numbers. Please help

function filteredSum(){

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var tsheet = ss.getSheetByName("Sheet1");

 var originalData = tsheet.getRange(10, 1, tsheet.getLastRow()-1, 2).getValues();
 var mindate = tsheet.getRange("C8").getValue();//starting date
 var maxdate = tsheet.getRange("D8").getValue();//end date

  var data = originalData.filter(function(item){return item[0] >= mindate && item[0] <= maxdate});

//here i got the array of arrays. and i'm stuck. how to get the sum of numbers


1 Answers

Владимир Смирнов On
var sum = data.reduce(function(a,b){
  return a + b[1];
}, 0);