git-subtree-dir: 2020 git-subtree-mainline:ab8f135946
git-subtree-split:aaabfa90c9
19 lines
541 B
JavaScript
19 lines
541 B
JavaScript
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) );
|
|
});
|