/** * @param {number[]}salary * @return {number} */ var average = function (salary) { const length = salary.length - 2; let min = Infinity, max = -Infinity, sum = 0; for (const num of salary) { min = Math.min(min, num); max = Math.max(max, num); sum += num; } return (sum - min - max) / length; };