Skip to content

Commit

Permalink
Fix IQR calculation per PR10
Browse files Browse the repository at this point in the history
  • Loading branch information
clody69 authored and gwatts committed Oct 14, 2012
1 parent 196c212 commit ae34cb3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,16 @@
var vl;
if (q === 2) {
vl = Math.floor(values.length / 2);
return values.length % 2 ? values[vl] : (values[vl] + values[vl + 1]) / 2;
return values.length % 2 ? values[vl] : (values[vl-1] + values[vl]) / 2;
} else {
vl = Math.floor(values.length / 4);
return values.length % 2 ? (values[vl * q] + values[vl * q + 1]) / 2 : values[vl * q];
if (values.length % 2 ) { // odd
vl = (values.length * q + q) / 4;
return vl % 1 ? (values[Math.floor(vl)] + values[Math.floor(vl) - 1]) / 2 : values[vl-1];
} else { //even
vl = (values.length * q + 2) / 4;
return vl % 1 ? (values[Math.floor(vl)] + values[Math.floor(vl) - 1]) / 2 : values[vl-1];

}
}
};

Expand Down

0 comments on commit ae34cb3

Please sign in to comment.