Skip to content

Instantly share code, notes, and snippets.

@ttsukagoshi
Last active January 17, 2020 04:22
Show Gist options
  • Save ttsukagoshi/e162a4298a8771e9dc7dbed5a17834a2 to your computer and use it in GitHub Desktop.
Save ttsukagoshi/e162a4298a8771e9dc7dbed5a17834a2 to your computer and use it in GitHub Desktop.
Returns the maximum value in a designated column of a Google Spreadsheet
/**
* Returns the maximum value in a designated column
* @param {sheet} sheet Target sheet
* @param {number} numCol Column number of target column
* @param {number} initialValue Initial value
* @return {number} max The largest number in target column
*/
function getMax(sheet, numCol, initialValue) {
initialValue = initialValue || 0;
var data = sheet.getRange(2, numCol, sheet.getLastRow()-1).getValues(); // First row of sheet used as header row
var max = data.reduce(function(accu, cur){return Math.max(accu, cur)}, initialValue);
return max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment