Skip to content

Instantly share code, notes, and snippets.

@manuelbieh
Created July 14, 2019 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelbieh/87f2138dd4d2afb5b1b46d96fec8f412 to your computer and use it in GitHub Desktop.
Save manuelbieh/87f2138dd4d2afb5b1b46d96fec8f412 to your computer and use it in GitHub Desktop.
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