Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Popular Words by mortonfox
"use strict";
function popularWords(text: string, words: string[]) {
return Object.fromEntries(words.map(w => [w, (text.match(new RegExp(`\\b${w}\\b`, 'gi')) || []).length]));
}
console.log('Example:')
console.log(popularWords(`
When I was One
I had just begun
When I was Two
I was nearly new`, ['i', 'was', 'three', 'near']))
April 23, 2020
Comments: