Problem with test on the server.
I run code in the browther and in webstorm - work corect, but checking on server lead to error -"Your result:{}" Is somebody know what is go on? my code:
function popularWords(text: string, words: string[]) { // your code here let myMap:Map<string,number> = setmap(words); for (let i = 0; i < words.length; i++) { let reg = new RegExp(\`\\b${words[i]}\\b\`,'ig'); // console.log(reg) let res = text.match(reg); if(res!==null){ myMap.set(words[i],res.length) } } return myMap;
}
function setmap(words: string[]) { let map = new Map(); for (let i = 0; i < words.length; i++) { map.set(words[i], 0); } return map;
}
console.log(popularWords(`\nWhen I was One\nI had just begun\nWhen I was Two\nI was nearly new\n`,["i","was","three","near"]));
result === Map { 'i' => 4, 'was' => 3, 'three' => 0, 'near' => 0 }