You are viewing a single comment's thread. Return to all comments →
JS solution
function processData(input) { let dataarray = input.split('\n') const N = dataarray.shift() const sentences = dataarray.splice(0, N) const T = dataarray.shift() const testcases = dataarray.splice(0, T) let counts = testcases.reduce((obj, c) => { obj[c] = 0; return obj; }, {}); for (let tc of testcases) { const regex = new RegExp(`\\b${tc.trim()}\\b`, 'g') for (let sentence of sentences) { const fsentence = sentence.replaceAll('or', 'our') let tccount = fsentence.match(regex)?.length if (tccount) counts[tc] = counts[tc] + tccount } } console.log(Object.values(counts).join('\n')) }
Seems like cookies are disabled on this browser, please enable them to open this website
UK and US: Part 2
You are viewing a single comment's thread. Return to all comments →
JS solution