var marks = "5 4 5 Н5 2 4 5 5 4 4 5".split(/\s+/).filter(isFinite).map(Number); var avg = marks.reduce((a, b) => a + b, 0) / marks.length; alert(avg);