Created
March 22, 2018 18:22
-
-
Save jhsuZerion/0f5cee9a9a5dbc95f92d029b7cc4acbc to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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