A JavaScript Package for calculating average from an array. Also it will work for non-number array and it will ignore the non-numbers.
npm install --save average-array
<script src="https://rawgit.com/Prosen-Ghosh/average-array/master/average.js"></script>
<script src="https://cdn.rawgit.com/Prosen-Ghosh/average-array/6dac0302/average.js"></script>
const avg = require('average-array');
avg([]);
//=> null
avg([1]);
//=> 1
avg([1,[]]);
//=> 1
avg([1,[],2]);
//=> 1.5
avg([1,2,3,4,5])
//=> 3
avg(); // without parameter this function will throw a type error
//=> TypeError: average() expects an array parameter
Prosen Ghosh prosenghosh25@gmail.com (https://bd.linkedin.com/in/prosen-ghosh-baba9aa8)
- MIT