Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
popular_words solution in Clear category for Popular Words by Jon_Red
'use strict';
import assert from'assert';
function popularWords(text:string,words:string[]){
var j={},w;
for(w of words)j[w]=text.toLowerCase().split(/\s/).filter(x=>x==w).length;
return j;
};
// self-checks
assert.equal(JSON.stringify(popularWords(
'\nWhen I was One\nI had just begun\nWhen I was Two\nI was nearly new',
['i','was','three','near']
)),JSON.stringify({i:4,was:3,three:0,near:0}));
July 22, 2020
Comments: