I have a list of 20 phrases that I want to count in an article.
Currently, I'm doing
let counts = phrases.map((phrase, idx) => {
phrase.usage = (articleBody.match(new RegExp(phrase.phrase, 'gi')) || []).length
return phrase
})
This requires me to do an expensive search each time. Is there some way to do it faster or all at once?
from How can I count the number of times different terms occur in a string string with JavaScript?
No comments:
Post a Comment