This commit is contained in:
2020-12-06 12:00:47 +00:00
parent 5557eb57e2
commit d97cf9f03a
3 changed files with 2200 additions and 0 deletions

18
06/part2.js Normal file
View File

@@ -0,0 +1,18 @@
const fs = require('fs');
Set.prototype.intersect = function(other) {
let out = new Set();
other.forEach((entry) => { this.has(entry) && out.add(entry) });
return out;
}
fs.readFile('input', (err, data) => {
if (err) throw err;
let groups = data.toString().split("\n\n").map((group) => {
let people = group.trim().split("\n").map((person) => new Set(person.trim().split("")));
return people.reduce((sum,person) => sum.intersect(person));
});
console.log( groups.reduce((sum, group) => sum + group.size, 0) );
});