part2 = str => {
const sets = str
.split("\n\n")
.map(group => group.replaceAll("\n",""))
.map(group => new Set(group))
const groups = str
.split("\n\n")
.map(group => group.split("\n"))
let answers = [];
for(let i = 0; i < groups.length; i++) {
let as = []
sets[i].forEach(answer => {
let all = true;
for(let j = 0; j < groups[i].length; j++) {
if(!groups[i][j].match(answer)) all = false;
}
if(all) as.push(answer)
})
answers.push(as);
}
return answers
.map(arr => arr.length)
.reduce((acc, inc) => acc + inc, 0)
}