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

Cooking unit tests in React Native

JavaScript Spread Syntax Explained

Frontend Interview Question: Create a Star Rating UI

Should I break-up because my boyfriend uses space instead of tabs ?

ES6 — Object vs. Map for storing key value pairs

What is loopback and how to make loopback rest API application

How to scrape data from Google Maps Pupputeer!

How to Upgrade from Angular 9 to Angular 10?

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
HopeGiometti

HopeGiometti

More from Medium

CRODO.IO — Stages

Stop Eating Dogs Meat

Cinderella

WHY IS IT IMPORTANT TO MASTER YOUR MIND?