Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Popular Words by Assper
"use strict";
function popularWords(text: string, words: string[]) {
return words.reduce((acc, word) => ({ ...acc, [word]: text.match(new RegExp(`\\b${word}\\b`, 'gi'))?.length || 0 }), {});
}
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 27, 2020