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
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How To Deploy a React app using Nginx and Ubuntu 18.04

Deno vs Node — comparison

Cookie Based Authentication using Flask and Vue.js: Part 1

A side-by-side image of the flask logo, followed by a picture of a stack of cookies

Laravel: WebAuthn the super easy way

How To Use jQuery

What is loopback and how to make loopback rest API application

Common Dilemma of using expo vs Vanilla React Native being solved.

Virtual DOM in React

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