From d7c04ab1d52eb2911c1da452030ac19747f32e84 Mon Sep 17 00:00:00 2001 From: murakawamasayuki <82010327+murakawamasayuki@users.noreply.github.com> Date: Mon, 19 Apr 2021 16:14:25 +0900 Subject: [PATCH 1/2] Update app.js --- app.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/app.js b/app.js index ad9a93a7..00b31858 100644 --- a/app.js +++ b/app.js @@ -1 +1,52 @@ '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(); +rl.on('line',lineString => { + const columns = lineString.split(','); + const year = parseInt(columns[0]); + const prefecture = columns[1]; + const popu = parseInt(columns[3]); + 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 pair1[1].change - pair2[1].change; + }); + const rankingStrings = rankingArray.map(([key, value],i) => { + return ( + (i + 1) + '位' + + key + + ': ' + + value.popu10 + + '=>' + + value.popu15 + + ' 変化率:' + + value.change + ); + + }); + console.log(rankingStrings); +}); From e62b95958623dba736838039e10bb582f52ccf12 Mon Sep 17 00:00:00 2001 From: murakawamasayuki <82010327+murakawamasayuki@users.noreply.github.com> Date: Mon, 19 Apr 2021 16:15:34 +0900 Subject: [PATCH 2/2] =?UTF-8?q?2010=20=E5=B9=B4=E3=81=8B=E3=82=89=202015?= =?UTF-8?q?=20=E5=B9=B4=E3=81=AB=E3=81=8B=E3=81=91=E3=81=A6=2015=E3=80=9C1?= =?UTF-8?q?9=20=E6=AD=B3=E3=81=AE=E4=BA=BA=E3=81=8C=E6=B8=9B=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E5=89=B2=E5=90=88=E3=81=AE=E9=83=BD=E9=81=93=E5=BA=9C?= =?UTF-8?q?=E7=9C=8C=E3=83=A9=E3=83=B3=E3=82=AD=E3=83=B3=E3=82=B0=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 00b31858..f21f9238 100644 --- a/app.js +++ b/app.js @@ -46,7 +46,7 @@ rl.on('close',() =>{ ' 変化率:' + value.change ); - + }); console.log(rankingStrings); });