From 40fb4d1b3581fd5ef1c2f87589d1e81ee4f47dd2 Mon Sep 17 00:00:00 2001 From: b1ancuito <460abe@gmail.com> Date: Sun, 18 Jan 2026 10:18:23 +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 | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/app.js b/app.js index ad9a93a..70c8199 100644 --- a/app.js +++ b/app.js @@ -1 +1,46 @@ '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 }); +const prefectureDataMap = new Map(); + +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){ + let value = null; + if (prefectureDataMap.has(prefecture)){ + value = prefectureDataMap.get(prefecture); + console.log('データあったよ!') + }else { + value = { + before: 0, + after: 0, + change: null + } + console.log('データなかったよ!') + } + 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