MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / subdomainVisits

Function subdomainVisits

JavaScript/Subdomain-Visit-Count.js:22–38  ·  view source on GitHub ↗
(cpdomains)

Source from the content-addressed store, hash-verified

20*/
21
22var subdomainVisits = function (cpdomains) {
23 if (!cpdomains || cpdomains.length <= 0) return [];
24 let map = new Map();
25 for (let dom of cpdomains) {
26 let [num, name] = dom.split(" ");
27 while (name.indexOf(".") >= 0) {
28 map.set(name, map.get(name) + Number(num) || Number(num));
29 name = name.substring(name.indexOf(".") + 1);
30 }
31 map.set(name, map.get(name) + Number(num) || Number(num));
32 }
33 let res = [];
34 for (let [key, value] of map.entries()) {
35 res.push(`${value} ${key}`);
36 }
37 return res;
38};

Callers

nothing calls this directly

Calls 3

setMethod · 0.80
pushMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected