Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Popular Words by andoreyrich
"use strict";
function popularWords(text: string, arr: string[]) {
const str = text.toLowerCase().replace(/\n/g, ' ').split(' ');
const dic = {};
for( let i of arr ){
dic[i] = str.filter(x => x == i).length;
}
return dic
}
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 30, 2020
Comments: