AdventOfCode2020/day_6/task_2.js
2020-12-06 17:54:51 +01:00

19 lines
507 B
JavaScript

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}`);