From 30c04711c9371d957af426d8b14100ef6d9f0255 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sun, 6 Dec 2020 14:10:21 +0100 Subject: [PATCH] Day 6: optimize q2 by starting from q1 answer --- 2020/day6/day6.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/2020/day6/day6.js b/2020/day6/day6.js index 8d25017..162dd2c 100755 --- a/2020/day6/day6.js +++ b/2020/day6/day6.js @@ -19,13 +19,11 @@ fs.readFile('input.txt', (err, data) => { if (q1Questions.indexOf(question) < 0) { q1Questions.push(question); } - - if (q2Questions.indexOf(question) < 0 && group.every(person => person.indexOf(question) >= 0)) { - q2Questions.push(question); - } } } + q2Questions = q1Questions.filter(question => group.every(person => person.indexOf(question) >= 0)); + q1 += q1Questions.length; q2 += q2Questions.length; }