Skip to content

Instantly share code, notes, and snippets.

@jhsuZerion
Created March 22, 2018 18:29
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/e7e3ee778c7f03ac92264d5dc8b44115 to your computer and use it in GitHub Desktop.
Save jhsuZerion/e7e3ee778c7f03ac92264d5dc8b44115 to your computer and use it in GitHub Desktop.
/**
* Find the minimum value of an element in a subform
* @param {array} myArray Subform
* @param {string} column Data column name to aggregate
* @return {int|boolean} The minimum value found, or false if array is undefined or data column name is not found
*/
function getMin(myArray, column) {
if (typeof myArray == "undefined" || myArray == null || Array.isArray(myArray) === false) return false;
var min_value = false;
for (var i = 0; i < myArray.length; i++) {
if (typeof myArray[i][column] !== "undefined") {
if (min_value === false) {
min_value = myArray[i][column];
} else {
if (Number(min_value) > Number(myArray[i][column])) {
min_value = myArray[i][column];
}
}
}
}
return min_value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment