Last active
October 18, 2021 23:00
-
-
Save lfelguetac/359878e306db7db595d5532d82581617 to your computer and use it in GitHub Desktop.
contador de palabras
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 cleanWords = (words: string) => { | |
return words.replace(/[,|.|:]/g, ''); | |
} | |
const countWords = (glosa: string) => { | |
const words = cleanWords(glosa).split(' '); | |
let output = [] as unknown as [{key: string, value: number}]; | |
for (const word of [...new Set(words)] ) { | |
output.push({key: word, value: words.filter(it => it === word).length}) | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment