summaryrefslogtreecommitdiffstats
path: root/day4/day4-1.js
diff options
context:
space:
mode:
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)