summaryrefslogtreecommitdiffstats
path: root/day4/day4-1.js
diff options
context:
space:
mode:
authorGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-07 23:03:50 +0100
committerGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-07 23:03:50 +0100
commitca03c82b68cea23752d78dc42aa5ab8c2ecb7ec7 (patch)
tree23d2be6d35c13f293c9257395072c1f4bdab421c /day4/day4-1.js
parent3700a9063725b001267730d6586d9cf905476cbb (diff)
downloadadvent_of_code_2020-ca03c82b68cea23752d78dc42aa5ab8c2ecb7ec7.tar.gz
advent_of_code_2020-ca03c82b68cea23752d78dc42aa5ab8c2ecb7ec7.tar.bz2
advent_of_code_2020-ca03c82b68cea23752d78dc42aa5ab8c2ecb7ec7.zip
day4
Diffstat (limited to 'day4/day4-1.js')
-rw-r--r--day4/day4-1.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/day4/day4-1.js b/day4/day4-1.js
new file mode 100644
index 0000000..7352d67
--- /dev/null
+++ b/day4/day4-1.js
@@ -0,0 +1,12 @@
+const data = require('./data')
+const req = ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid']
+const valid = data
+ .replace(/\n\r/g, "\n")
+ .split(/\n{2,}/g)
+ .map(s => s.replace(/\n/g,"").split(' '))
+ .map(a => a.filter(Boolean))
+ .map(a => a.map(s => s.split(':')))
+ .map(o => req.every(r => o.map(o => o[0]).includes(r)))
+ .filter(v => v === true).length
+
+console.log(valid)