JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="field_1" value="1">
<input type="text" id="field_2" value="2">
<input type="text" id="field_3" value="3">
<input type="text" id="field_4" value="">
<input type="text" id="field_5" value="5">
<input type="text" id="field_6" value="sdfsdfsdf">
<input type="text" id="field_7" value="7">
<input type="text" id="field_8" value="8">
<input type="text" id="field_9" value="9">
<input type="text" id="field_10" value="10">
<p>
<label for="min">Minimum</label>
<input type="text" id="min" name="min">
</p>
<p>
<label for="max">Maximum</label>
<input type="text" id="max" name="max">
</p>
<p>
<label for="avg">Average</label>
<input type="text" id="avg" name="avg">
</p>
JavaScript
Array.prototype.avg = function() {
var total = this[0];
var len = this.length;
for (var i = 1; i != len; i++) total += this[i];
return total / len;
}
Array.prototype.min = function() {
return Math.min.apply( Math, this );
}
Array.prototype.max = function() {
return Math.max.apply( Math, this );
}
var values = $("input[id^='field_']").map(function(){
var value = $(this).val();
if (value.length == 0 || isNaN(value)) {
return 0;
} else {
return parseFloat(value);
}
}).get();
$('#max').val(values.max());
$('#min').val(values.min());
$('#avg').val(values.avg());