Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 0ecfc99

Browse files
committed
lint file and remove unecessary consts
1 parent 0d01f74 commit 0ecfc99

File tree

1 file changed

+17
-38
lines changed

1 file changed

+17
-38
lines changed

most-frequent-words/src/app.js

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,22 @@ import { join } from 'path'
22
import * as utils from './utils/functions'
33

44
const subtitlesDirectory = join(__dirname, '..', 'assets', 'subtitles')
5+
const patternsToRemove = ['.', '?', '-', ',', '"', '♪', '_', '<i>', '</i>', '\r', '[', ']', '(', ')']
56
const filesExtension = '.srt'
6-
const patternsToRemove = [
7-
'.', '?', '-', ',', '"', '♪',
8-
'_', '<i>', '</i>', '\r',
9-
'[', ']', '(', ')'
10-
]
117

12-
function makeWordsGroup (words) {
13-
const initialState = {}
14-
15-
return Object.values(words.reduce((groupedWords, word) => {
16-
const text = word.toLowerCase()
17-
const quantity = groupedWords[text] ? groupedWords[text].quantity + 1 : 1
18-
19-
groupedWords[text] = { word: groupedWords[text], quantity }
20-
21-
return groupedWords
22-
}, initialState))
23-
}
24-
25-
async function getWordsFromSubtitles (directory, targetExtension) {
26-
const allFiles = await utils.getFilesFromDirectory(directory)
27-
const targetFiles = await utils.filesEndingWith(allFiles, targetExtension)
28-
const subtitles = await utils.readFiles(targetFiles)
29-
const mergedContent = utils.mergeContent(subtitles)
30-
const splittedContent = utils.splitStringByPattern(mergedContent, '\n')
31-
const stringsWithoutOnlySpaces = utils.deleteEmptyStrings(splittedContent.map(string => string))
32-
const stringsWithoutDuration = utils.deleteWhenIncludes(stringsWithoutOnlySpaces, '-->')
33-
const stringsWithoutNumbers = utils.deleteWhenHasOnlyNumber(stringsWithoutDuration)
34-
const sanitizedStrings = utils.deletePatternsFromTexts(stringsWithoutNumbers, patternsToRemove)
35-
const sanatizedMergedContent = utils.mergeContent(sanitizedStrings)
36-
const splittedWords = utils.splitStringByPattern(sanatizedMergedContent, ' ')
37-
const wordsNotEmpty = utils.deleteEmptyStrings(splittedWords)
38-
const wordsWithoutNumbers = utils.deleteWhenHasOnlyNumber(wordsNotEmpty)
39-
const groupedWords = makeWordsGroup(wordsWithoutNumbers)
40-
41-
return groupedWords
42-
}
43-
44-
getWordsFromSubtitles(subtitlesDirectory, filesExtension).then(console.log)
8+
utils.getFilesFromDirectory(subtitlesDirectory)
9+
.then(utils.textsEndingWith(filesExtension))
10+
.then(utils.readFiles)
11+
.then(utils.mergeContent)
12+
.then(utils.splitStringByPattern('\n'))
13+
.then(utils.deleteEmptyStrings)
14+
.then(utils.deleteWhenIncludes('-->'))
15+
.then(utils.deleteWhenHasOnlyNumber)
16+
.then(utils.deletePatternsFromTexts(patternsToRemove))
17+
.then(utils.mergeContent)
18+
.then(utils.splitStringByPattern(' '))
19+
.then(utils.deleteEmptyStrings)
20+
.then(utils.deleteWhenHasOnlyNumber)
21+
.then(utils.groupWords)
22+
.then(utils.orderByAttrNumeric('quantity', 'desc'))
23+
.then(console.log)

0 commit comments

Comments
 (0)