const fs = require('fs'); const file = fs.readFileSync(__dirname + '/input.txt').toString('utf-8'); const groups = file.split('\n\n'); let total = 0; groups.forEach(answers => { answers = answers .split('\n'); let answered = {}; answers.forEach( an => an.split('').forEach(a => answered[a] ? answered[a]++ : answered[a] = 1 )); for (const [key, value] of Object.entries(answered)) { if (value == answers.length) total++; } }); console.log(`Total: ${total}`);