From aa6791969030beb0f904375977dccc3c4d8c9608 Mon Sep 17 00:00:00 2001 From: Yuzuko Niigaki Date: Wed, 3 Mar 2021 15:31:41 +0900 Subject: [PATCH 1/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 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/app.js b/app.js index ad9a93a7..577d0300 100644 --- a/app.js +++ b/app.js @@ -1 +1,49 @@ 'use strict'; +const fs = require('fs'); +const readline = require('readline'); +const rs = fs.createReadStream('./popu-pref.csv'); +const rl = readline.createInterface({ input: rs, output: {} }); +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[2]); + if (year === 2010 || year === 2015) { + let value = prefectureDataMap.get(prefecture); + if (!value) { + value = { + popu10: 0, + popu15: 0, + change: null + } + } + if (year === 2010) { + value.popu10 = popu; + } + if (year === 2015) { + value.popu15 = popu; + } + prefectureDataMap.set(prefecture, value); + } +}) +rl.on('close', () => { + for (let [key, value] of prefectureDataMap) { + value.change = value.popu15 / value.popu10; + } + const rankingArray = Array.from(prefectureDataMap).sort((pair1, pair2) => { + return pair2[1].change - pair1[1].change; + }) + const rankingString = rankingArray.map(([key, value]) => { + return ( + key + + ': ' + + value.popu10 + + '=>' + + value.popu15 + + ' 変化率' + + value.change + ); + }) + console.log(rankingString); +}) \ No newline at end of file From 0740a4fe82d64c96a91d09e8f4214768446626c3 Mon Sep 17 00:00:00 2001 From: Yuzuko Niigaki Date: Wed, 3 Mar 2021 15:40:12 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B8=9B=E5=B0=91=E3=83=A9=E3=83=B3?= =?UTF-8?q?=E3=82=AD=E3=83=B3=E3=82=B0=E3=81=AB=E6=94=B9=E5=A4=89=E3=80=81?= =?UTF-8?q?=E9=A0=86=E4=BD=8D=E3=81=AE=E5=87=BA=E5=8A=9B=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 577d0300..5bbe66f1 100644 --- a/app.js +++ b/app.js @@ -32,10 +32,12 @@ rl.on('close', () => { value.change = value.popu15 / value.popu10; } const rankingArray = Array.from(prefectureDataMap).sort((pair1, pair2) => { - return pair2[1].change - pair1[1].change; + return pair1[1].change - pair2[1].change; }) - const rankingString = rankingArray.map(([key, value]) => { + const rankingString = rankingArray.map(([key, value], i) => { return ( + (i + 1) + + '位 ' + key + ': ' + value.popu10 +