Created
March 11, 2019 11:21
-
-
Save ruslanys/4f12c3d9c8a2cfcf55ac8385c17b4fd4 to your computer and use it in GitHub Desktop.
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 characters
| #!/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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment