← Back to challenges

Trimmed Averages

JavaScriptHardnumbersmatharrays

Instructions

Given an array of numbers, remove the largest and smallest numbers, and calculate the average of the remaining numbers.

Examples

trimmedAverages([4, 5, 7, 100]) ➞ 6
// Average of 5 and 7

trimmedAverages([10, 25, 5, 15, 20]) ➞ 15
// Average of 10, 15 and 20

trimmedAverages([1, 1, 1]) ➞ 1
// 1

Notes

  • Round to the nearest whole number.
  • Array size is greater than 2.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Buggy Uppercase Counting