Skip to content

Instantly share code, notes, and snippets.

@jhsuZerion
Created March 22, 2018 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhsuZerion/0f5cee9a9a5dbc95f92d029b7cc4acbc to your computer and use it in GitHub Desktop.
Save jhsuZerion/0f5cee9a9a5dbc95f92d029b7cc4acbc to your computer and use it in GitHub Desktop.
/**
* Find the maximum value of an element in a subform
* @param {array} myArray Subform
* @param {string} column Data column name to aggregate
* @return {int|boolean} The maximum value found, or false if array is undefined or data column name is not found
*/
function getMax(myArray, column) {
if (typeof myArray == "undefined" || myArray == null || Array.isArray(myArray) === false) return false;
var max_value = false;
for (var i = 0; i < myArray.length; i++) {
if (typeof myArray[i][column] !== "undefined") {
if (max_value === false) {
max_value = myArray[i][column];
} else {
if (Number(max_value) < Number(myArray[i][column])) {
max_value = myArray[i][column];
}
}
}
}
return max_value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment