Skip to content

Instantly share code, notes, and snippets.

@lfelguetac
Last active October 18, 2021 23:00
Show Gist options
  • Save lfelguetac/359878e306db7db595d5532d82581617 to your computer and use it in GitHub Desktop.
Save lfelguetac/359878e306db7db595d5532d82581617 to your computer and use it in GitHub Desktop.
contador de palabras
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