29 lines
681 B
JavaScript
29 lines
681 B
JavaScript
'use strict';
|
|
|
|
const fs = require('fs').promises;
|
|
|
|
async function init() {
|
|
const rawDictionary = await fs.readFile('./mash-words.json', 'utf8');
|
|
const dictionary = JSON.parse(rawDictionary);
|
|
|
|
const averages = Object.entries(dictionary)
|
|
.reduce((accAverages, [length, anagramsMap]) => {
|
|
const anagramsList = Object.values(anagramsMap);
|
|
const total = anagramsList.reduce((acc, words) => acc + words.length, 0);
|
|
const average = total / anagramsList.length;
|
|
|
|
return {
|
|
...accAverages,
|
|
[length]: average,
|
|
};
|
|
}, {});
|
|
|
|
console.log(averages);
|
|
|
|
// CSV
|
|
console.log(Object.keys(averages).join(','));
|
|
console.log(Object.values(averages).join(','));
|
|
}
|
|
|
|
init();
|