const {sum, n} = '5 4 5 Н5 2 4 5 5 4 4 5'.split(/\s+/).reduce(({sum, n},b)=> (sum += (b == +b ? (n++, +b) : 0), {sum, n}), {sum : 0, n : 0}); alert(sum/n);