From f14a7b4cb7547b62a039bb1a2ebcb648c5326f5a Mon Sep 17 00:00:00 2001 From: isokaze Date: Tue, 28 Jul 2026 22:03:34 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E6=9B=B8=E3=81=8D=E5=87=BA=E3=81=97=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app.js b/app.js index ad9a93a..9f37030 100644 --- a/app.js +++ b/app.js @@ -1 +1,17 @@ 'use strict'; +const fs = require('node:fs'); +const readline = require('node:readline'); +const rs = fs.createReadStream('./popu-pref.csv'); +const rl = readline.createInterface({ input: rs }); +rl.on('line', lineString => { + const columns = lineString.split(','); + const year = parseInt(columns[0]); + const prefecture = columns[1]; + const popu = parseInt(columns[3]); + if (year === 2016 || year === 2021){ + console.log(year); + console.log(prefecture); + console.log(popu); + } + +}); \ No newline at end of file From 8df4466c326a76de6dc6caa36629aeff4652da98 Mon Sep 17 00:00:00 2001 From: isokaze Date: Mon, 3 Aug 2026 10:38:58 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=A9=E3=83=B3=E3=82=AD=E3=83=B3?= =?UTF-8?q?=E3=82=B0=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 | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 9f37030..e6598ea 100644 --- a/app.js +++ b/app.js @@ -3,15 +3,42 @@ const fs = require('node:fs'); const readline = require('node:readline'); const rs = fs.createReadStream('./popu-pref.csv'); const rl = readline.createInterface({ input: rs }); +const prefectureDataMap = new Map(); // key: 都道府県 value: 集計データのオブジェクト rl.on('line', lineString => { const columns = lineString.split(','); const year = parseInt(columns[0]); const prefecture = columns[1]; const popu = parseInt(columns[3]); if (year === 2016 || year === 2021){ - console.log(year); - console.log(prefecture); - console.log(popu); + let value = null; + if (prefectureDataMap.has(prefecture)) { + value = prefectureDataMap.get(prefecture); + } else { + value = { + before: 0, + after: 0, + change: null + }; + } + if (year === 2016) { + value.before = popu; + } + if (year === 2021) { + value.after = popu; + } + prefectureDataMap.set(prefecture, value); } +}); +rl.on('close', () => { + for (const [key, value] of prefectureDataMap){ + value.change = value.after / value.before; + } + const rankingArray = Array.from(prefectureDataMap).sort((pair1, pair2) => { + return pair2[1].change - pair1[1].change; + }); + const rankingStrings = rankingArray.map(([key, value]) => { + return `${key}: ${value.before}=>${value.after} 変化率: ${value.change}`; + }); + console.log(rankingStrings); }); \ No newline at end of file