diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-11-20 02:31:29 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-11-20 02:31:29 +0900 |
| commit | 74c79ddbbd882ccc5fc5ff43e8685feb285627cb (patch) | |
| tree | 5671cbc5454f135fa87c4c2f948a6346bfce9e53 /src/web/app/common/scripts | |
| parent | Merge pull request #930 from syuilo/greenkeeper/awesome-typescript-loader-3.4.0 (diff) | |
| download | sharkey-74c79ddbbd882ccc5fc5ff43e8685feb285627cb.tar.gz sharkey-74c79ddbbd882ccc5fc5ff43e8685feb285627cb.tar.bz2 sharkey-74c79ddbbd882ccc5fc5ff43e8685feb285627cb.zip | |
MAKE CHARTS GREAT AGAIN
Diffstat (limited to 'src/web/app/common/scripts')
| -rw-r--r-- | src/web/app/common/scripts/get-median.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/web/app/common/scripts/get-median.ts b/src/web/app/common/scripts/get-median.ts new file mode 100644 index 0000000000..91a415d5b2 --- /dev/null +++ b/src/web/app/common/scripts/get-median.ts @@ -0,0 +1,11 @@ +/** + * 中央値を求めます + * @param samples サンプル + */ +export default function(samples) { + if (!samples.length) return 0; + const numbers = samples.slice(0).sort((a, b) => a - b); + const middle = Math.floor(numbers.length / 2); + const isEven = numbers.length % 2 === 0; + return isEven ? (numbers[middle] + numbers[middle - 1]) / 2 : numbers[middle]; +} |