Solving Popular Algorithms: Average Salary

Because it means I correctly solved this problem!
s = [4000,3000,1000,2000]
let max = 0
let min = Number.MAX_SAFE_INTEGER
for (let i = 0; i < s.length; i++) {
if (s[i] > max) {
max = s[i]
}
if (s[i] < min) {
min = s[i]
}
}
//removes the max value
for (let j = 0; j < s.length; j++) {
if (s[j] === max) {
s.splice(j, 1)
}
}//removes the min value
for (let y = 0; y < s.length; y++) {
if (s[y] === min) {
s.splice(y, 1)
}
}
let total = 0for (let x = 0; x < s.length; x++) {
total += s[x]
}
return total/s.length
avSal = (s) => {
let max = 0
let min = Number.MAX_SAFE_INTEGER
let total = 0
//finds the max and min values
for (let i = 0; i < s.length; i++) {
if (s[i] > max) {
max = s[i]
}
if (s[i] < min) {
min = s[i]
}
}
//removes the max value
for (let j = 0; j < s.length; j++) {
if (s[j] === max) {
s.splice(j, 1)
}
} //removes the min value
for (let y = 0; y < s.length; y++) {
if (s[y] === min) {
s.splice(y, 1)
}
}
//calculates the average
for (let x = 0; x < s.length; x++) {
total += s[x]
}
return total/s.length
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store