(numbers)
| 10 | * @example mean([10, 40, 100, 20]) = 42.5 |
| 11 | */ |
| 12 | const mean = (numbers) => { |
| 13 | if (!Array.isArray(numbers)) { |
| 14 | throw new TypeError('Invalid Input') |
| 15 | } else if (numbers.length === 0) { |
| 16 | throw new Error('Array is empty') |
| 17 | } |
| 18 | |
| 19 | let total = 0 |
| 20 | numbers.forEach((num) => { |
| 21 | if (typeof num !== 'number') { |
| 22 | throw new TypeError('Invalid Input') |
| 23 | } |
| 24 | total += num |
| 25 | }) |
| 26 | |
| 27 | return total / numbers.length |
| 28 | } |
| 29 | |
| 30 | export { mean } |
no outgoing calls
no test coverage detected