From 0508d129c7a528514ad505164c38f8dfeea99001 Mon Sep 17 00:00:00 2001 From: kohei Date: Mon, 19 Nov 2018 18:46:47 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=AE=9F=E8=A1=8C=E3=83=97?= =?UTF-8?q?=E3=83=AD=E3=82=BB=E3=82=B9=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/percentage.jsx | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/components/percentage.jsx b/components/percentage.jsx index 038e957..d2aa94d 100644 --- a/components/percentage.jsx +++ b/components/percentage.jsx @@ -1,24 +1,20 @@ export default ({ activity }) => { - const leftActivity = activity - .filter(a => a.ch === "l") - .map(a => a.endTime - a.startTime) - .reduce((a, c) => a + c, 0); - const rightActivity = activity - .filter(a => a.ch === "r") - .map(a => a.endTime - a.startTime) - .reduce((a, c) => a + c, 0); + const leftActivity = activity.filter(a => a.ch === "l"), + rightActivity = activity.filter(a => a.ch === "r"); + const [l, r] = [leftActivity, rightActivity].map(activity => { + return activity + .map(a => a.endTime - a.startTime) + .reduce((a, c) => a + c, 0); + }); + const sum = l + r; return (
会話時間 (ms)
-
{leftActivity + rightActivity}
+
{sum}
会話の割合
- 左{" "} - - {leftActivity / (leftActivity + rightActivity)} - {" "} - 右 + 左 {l / sum}
);