Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
PW - SLR - Reduce, Match, Null OR Catch solution in Clear category for Popular Words by Taylor_Page
"use strict";
function popularWords(text: string, words: string[]) {
return words.reduce((k,v) => (k[v] = text.match(RegExp(`(\\b${v}\\b)`, "gi"))?.length || 0, k), {})
}
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']))
June 5, 2020
Comments: