Created
July 14, 2019 20:05
-
-
Save manuelbieh/87f2138dd4d2afb5b1b46d96fec8f412 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const glob = require('glob'); | |
const fs = require('fs'); | |
const files = glob.sync(process.cwd() + '/{src,config,scripts}/**/*.{js,jsx,ts,tsx}', {nodir: true}); | |
const letterCount = files | |
.map((file) => fs.readFileSync(file, { encoding: 'utf-8'})) | |
.map((fileContent) => fileContent.split('')) | |
.reduce((acc, lettersOfFile) => { | |
lettersOfFile.forEach((letter) => { | |
acc[letter] = acc[letter] ? acc[letter]+1 : 1; | |
}) | |
return acc; | |
}, {}); | |
const sorted = Object.entries(letterCount).sort((a, b) => b[1] < a[1] ? -1 : 1) | |
console.table(sorted); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment