Array.reduce to maximum value
Using Array.reduce to find the maximum value in an Array.
HTML
<p>Maximum value: <span id="max"></span>
</p>
<hr/>
<a href="http://live24u.com/" target="_blank"><button>Example</button></a>
-------
<a href="http://live24u.com/w3free/" target="_blank"><button>Download</button></a>
<hr/>
JavaScript
(function () {
'use strict';
function sum(previous, current) {
return previous + (current === undefined ? 0: current);
}
var data = [{
v: [1, 3, 4]
}, {
v: [7, 6, 5]
}, {
v: [9, 10, 1]
}, {
v: [3, 8, 2]
}, {
v: [2, 7, 8]
}, {
v: [11, 5, 6]
}, {
v: [6, 3, 1]
}, {
v: [4, 2, 1]
}];
var maximum = data.reduce(function (previous, current) {
return Math.max(isNaN(previous) ? previous.v.reduce(sum) : previous, current.v.reduce(sum));
});
document.getElementById('max').innerHTML = maximum;
}());