From 3606b6cf7732088fbed6d91c450e2177745763e1 Mon Sep 17 00:00:00 2001
From: Naoki Mayuzumi <naokim0802@yahoo.co.jp>
Date: Fri, 2 Jul 2021 15:29:12 +0900
Subject: [PATCH] =?UTF-8?q?=E3=83=A9=E3=83=B3=E3=82=AD=E3=83=B3=E3=82=B0?=
 =?UTF-8?q?=E3=81=AE=E5=AE=9F=E8=A3=85=E5=AE=8C=E4=BA=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app.js | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/app.js b/app.js
index ad9a93a7..7182c97a 100644
--- a/app.js
+++ b/app.js
@@ -1 +1,45 @@
 'use strict';
+const fs = require('fs');
+const readline = require('readline');
+const rs = fs.ReadStream('./popu-pref.csv');
+const rl = readline.createInterface({ 'input': rs, 'output': {}});
+const map = new Map(); // key: 都道府県 value: 集計データのオブジェクト
+rl.on('line', (lineString) => {
+	const columns = lineString.split(',');
+	const year = parseInt(columns[0]);
+	const prefecture = columns[2];
+	const popu = parseInt(columns[7]);
+	if (year === 2010 || year === 2015) {
+		let value = map.get(prefecture);
+		if (!value) {
+		value = {
+			popu10: 0,
+			popu15: 0,
+			change: null
+		};
+	}
+	if (year === 2010) {
+		value.popu10 += popu;
+	}
+	if (year === 2015) {
+		value.popu15 += popu;
+	}
+	map.set(prefecture, value);
+	}
+});
+rl.resume();
+rl.on('close', () => {
+	for (let pair of map) {
+		const value = pair[1];
+		value.change = value.popu15 / value.popu10;
+	}
+	const rankingArray = Array.from(map).sort((pair1, pair2) => {
+		return pair2[1].change - pair1[1].change;
+	});
+	const rankingStrings = rankingArray.map((pair) => {
+		return pair[0] + ': ' + pair[1].popu10 + '=>' + pair[1].
+	popu15 + ' 変化率:' + pair[1].change;
+	});
+	console.log(map);
+});
+