Skip to content

Commit

Permalink
Stop bignumber stats with no data showing as NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartlangridge committed Apr 18, 2018
1 parent 74c6208 commit 93d6c2d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions widgets/widgetUtils.js
@@ -1,10 +1,10 @@
const moment = require("moment");

var averageArray = arr => arr.reduce( ( p, c ) => p + c, 0 ) / arr.length;
var medianArray = arr => arr[Math.floor(arr.length/2)];
var averageArray = arr => arr.length ? arr.reduce( ( p, c ) => p + c, 0 ) / arr.length : 0;
var medianArray = arr => arr.length ? arr[Math.floor(arr.length/2)] : 0;
// this isn't strictly 95th percentile, but it's likely to be about right
// assuming a reasonably even distribution of possibilities
var pc95Array = arr => arr[Math.floor(0.95*(arr.length-1))];
var pc95Array = arr => arr.length ? arr[Math.floor(0.95*(arr.length-1))] : 0;

module.exports.averageArray = averageArray;
module.exports.medianArray = medianArray;
Expand Down

0 comments on commit 93d6c2d

Please sign in to comment.