Last active
January 17, 2020 04:22
-
-
Save ttsukagoshi/e162a4298a8771e9dc7dbed5a17834a2 to your computer and use it in GitHub Desktop.
Returns the maximum value in a designated column of a Google Spreadsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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