From c5e0fd313aa1798f09e5f011ae282b33acde9a43 Mon Sep 17 00:00:00 2001 From: susuki-kareno Date: Sat, 11 May 2024 18:31:27 +0900 Subject: [PATCH 1/5] complete ranking implementation. --- app.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/app.js b/app.js index ad9a93a7..0ab0ceed 100644 --- a/app.js +++ b/app.js @@ -1 +1,57 @@ 'use strict'; + +const fs = require('fs'); +const readline = require('readline'); + +const rs = fs.ReadStream('./popu-pref.csv'); +const rl = readline.createInterface({ 'input': rs, 'output': {}}); + +const map = new Map(); + +rl.on('line', (lineString) => +{ + const columns = lineString.split(','); + const year = parseInt(columns[0]); + const prefecture = columns[2]; + const popu = parseInt(columns[7]); + if (year === 2010 || year === 2015) + { + let value = map.get(prefecture); + if (!value) + { + value = { popu2010: 0, popu2015: 0, change: null }; + } + if (year === 2010) + { + value.popu2010 += popu; + } + if (year === 2015) + { + value.popu2015 += popu; + } + map.set(prefecture, value); + } +}); + +rl.resume(); + +rl.on('close', () => +{ + for(let pair of map) + { + const value = pair[1]; + value.change = value.popu2015 / value.popu2010; + } + + const rankingArray = Array.from(map); + rankingArray.sort((pair1, pair2) => + { + return pair2[1].change - pair1[1].change; + }); + + const rankingStrings = rankingArray.map((pair) => + { + return pair[0] + ':' + pair[1].popu2010 + '=>' + pair[1].popu2015 + ' 変化率:' + pair[1].change; + }); + console.log(rankingStrings); +}); From 889dfe913cd72b198091cccc5960d2238215a727 Mon Sep 17 00:00:00 2001 From: susuki-kareno Date: Sat, 11 May 2024 18:33:52 +0900 Subject: [PATCH 2/5] sort descending. --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 0ab0ceed..364f1f45 100644 --- a/app.js +++ b/app.js @@ -46,7 +46,7 @@ rl.on('close', () => const rankingArray = Array.from(map); rankingArray.sort((pair1, pair2) => { - return pair2[1].change - pair1[1].change; + return pair1[1].change - pair2[1].change; }); const rankingStrings = rankingArray.map((pair) => From e8d21eef03e300e2cbc8009e511597c83d4f0329 Mon Sep 17 00:00:00 2001 From: susuki-kareno Date: Sun, 12 May 2024 12:38:11 +0900 Subject: [PATCH 3/5] mod test --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 364f1f45..0377e8eb 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,5 @@ 'use strict'; - +# const fs = require('fs'); const readline = require('readline'); From 27777655dd86cd8d9aac149a42807daad8a0123e Mon Sep 17 00:00:00 2001 From: susuki-kareno Date: Sun, 12 May 2024 12:49:03 +0900 Subject: [PATCH 4/5] mod test2 --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 0377e8eb..364f1f45 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,5 @@ 'use strict'; -# + const fs = require('fs'); const readline = require('readline'); From a19ea95b198553520a118fd22331fc8534d847bb Mon Sep 17 00:00:00 2001 From: susuki-kareno Date: Sun, 12 May 2024 12:54:51 +0900 Subject: [PATCH 5/5] mod test3 --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 364f1f45..f8230f88 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,5 @@ 'use strict'; - +## const fs = require('fs'); const readline = require('readline');