From 1d4e437f2874c0e761b938b2c470bd8bb91ff6e1 Mon Sep 17 00:00:00 2001 From: Yoshineko12 <251zs02143@student.zen.ac.jp> Date: Sun, 17 Aug 2025 20:57:49 +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..15ca592 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); + } 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 [prefecture, value] of prefectureDataMap) { + value.change = value.after - value.before; + } + + console.log(prefectureDataMap); +}); \ No newline at end of file