Created
March 11, 2019 11:21
-
-
Save ruslanys/4f12c3d9c8a2cfcf55ac8385c17b4fd4 to your computer and use it in GitHub Desktop.
Revisions
-
ruslanys created this gist
Mar 11, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ #!/usr/bin/env node var fs = require('fs'); // arg const filePath = process.argv[2]; // read file let content = fs.readFileSync(filePath, 'utf8'); // process content let processedContent = content .replace('\n', ' ') .replace(/\W/g, ' '); let words = processedContent.split(' '); let set = new Set(); for (let i = 0; i < words.length; i++) { let word = words[i]; let processedWord = word.trim().toLocaleLowerCase(); if (processedWord.length === 0) { continue; } set.add(processedWord) } // output console.log('Unique words: ' + set.size);