compute-midmean
Advanced tools
Comparing version 1.0.1 to 1.0.3
@@ -64,2 +64,5 @@ /** | ||
} | ||
if ( arr.length < 3 ) { | ||
throw new TypeError( 'midmean()::invalid input argument. Midmean not applicable.' ); | ||
} | ||
if ( !sorted ) { | ||
@@ -73,11 +76,17 @@ arr = arr.slice(); | ||
delta, | ||
q1, | ||
q3; | ||
low, | ||
high; | ||
// Get the indices for the first and third quartiles...(zero base) | ||
q1 = Math.floor( len*0.25 ); | ||
q3 = Math.floor( len*0.75 ); | ||
// Quartiles sit between values... | ||
if ( len%4 === 0 ) { | ||
low = len*0.25; | ||
high = len*0.75 - 1; | ||
} | ||
else { | ||
low = Math.ceil( len*0.25 ); | ||
high = Math.floor( len*0.75 ) - 1; | ||
} | ||
// Compute an arithmetic mean... | ||
for ( var i = q1, j = q3+1; i < j; i++ ) { | ||
for ( var i = low; i <= high; i++ ) { | ||
N += 1; | ||
@@ -84,0 +93,0 @@ delta = arr[ i ] - mean; |
{ | ||
"name": "compute-midmean", | ||
"version": "1.0.1", | ||
"version": "1.0.3", | ||
"description": "Computes the interquartile mean (midmean) of a numeric array.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -64,3 +64,2 @@ Midmean | ||
## Notes | ||
@@ -70,3 +69,9 @@ | ||
The midmean includes the values located between *but not including* the first and third quartiles. In the following examples, the values included in the midmean are in bold. | ||
* [1,2,__3,4,5,6__,7,8] -> midmean: 4.5 | ||
* [1,2,__3,4,5__,6,7] -> midmean: 4 | ||
## Tests | ||
@@ -73,0 +78,0 @@ |
8017
89
131