danik.js,
var arr = [9,7,1,8], a = [1, 2, 3, 4, 5, 6, 7, 8] ;
function get(a) {
var c, e = a[0] > a[1] ? (c = a[1], a[0]) : (c = a[0], a[1]);
for (var b = 0; b < a.length; b += 2) {
var d, f = a[b] > a[b + 1] ? (d = a[b + 1], a[b]) : (d = a[b], a[b + 1]);
f < e && (e = f);
d > c && (c = d)
}
return (c + e) / 2
};
alert([get(arr),get(a)].join('\n'));