diff --git a/app.js b/app.js index ff2e98b9..dfeec716 100644 --- a/app.js +++ b/app.js @@ -1,11 +1,11 @@ -'use strict'; -const fs = require('fs'); -const readline = require('readline'); -const rs = fs.createReadStream('./popu-pref.csv'); -const rl = readline.createInterface({ 'input': rs, 'output': {} }); +"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(','); +rl.on("line", (lineString) => { + const columns = lineString.split(","); const year = parseInt(columns[0]); const prefecture = columns[1]; const popu = parseInt(columns[3]); @@ -15,7 +15,7 @@ rl.on('line', (lineString) => { value = { popu10: 0, popu15: 0, - change: null + change: null, }; } if (year === 2010) { @@ -27,15 +27,26 @@ rl.on('line', (lineString) => { prefectureDataMap.set(prefecture, value); } }); -rl.on('close', () => { - for (let [key, value] of prefectureDataMap) { +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; + return pair1[1].change - pair2[1].change; }); - const rankingStrings = rankingArray.map(([key, value]) => { - return key + ': ' + value.popu10 + '=>' + value.popu15 + ' 変化率:' + value.change; + const rankingStrings = rankingArray.map(([key, value], i) => { + return ( + i + + 1 + + "位" + + key + + ": " + + value.popu10 + + "=>" + + value.popu15 + + " 変化率:" + + value.change + ); }); console.log(rankingStrings); -}); \ No newline at end of file +});