the leet code question states,
You are given an array of unique integers salary where salary[i] is the salary of the ith employee.
Return the average salary of employees excluding the minimum and maximum salary. Answers within 10-5 of the actual answer will be accepted.
i expect to start off the first indices with let sal = salary[0]
, i wanted to compare the other salaries to salary[0]
and if it was less, i wanted to push the lower salaries into a new array. however im not sure how to seperate the lowest salary or finish the problem
/**
* @param {number[]} salary
* @return {number}
*/
var average = function(salary) {
let sal = salary[0]
for(let i = 1; i < salary.length; i++){
if (sal > salary[i]) {
salary.map()
}
}
};
4
Answers
For that I would sort the array, and then remove the first and last elements, since the first one will be the lowest salary, and the last one will be the highest salary. Then, with the trimmed array, I’d do the average:
you can first sort the array then do what ever you want