summaryrefslogtreecommitdiffstats
path: root/day2/day2-1.js
diff options
context:
space:
mode:
authorGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-07 22:36:36 +0100
committerGravatar Piotr Russ <piotr.russ@betvictor.com> 2020-12-07 22:36:36 +0100
commit5e34312e42721aae0d8919df7ef31ffaff435555 (patch)
tree8c37ef6255c0973f205308b4288e6312ddc6b732 /day2/day2-1.js
parent62493a5b11085b8214188e0b9cee3aae24302c65 (diff)
downloadadvent_of_code_2020-5e34312e42721aae0d8919df7ef31ffaff435555.tar.gz
advent_of_code_2020-5e34312e42721aae0d8919df7ef31ffaff435555.tar.bz2
advent_of_code_2020-5e34312e42721aae0d8919df7ef31ffaff435555.zip
day2
Diffstat (limited to 'day2/day2-1.js')
-rw-r--r--day2/day2-1.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/day2/day2-1.js b/day2/day2-1.js
new file mode 100644
index 0000000..429a900
--- /dev/null
+++ b/day2/day2-1.js
@@ -0,0 +1,14 @@
+const data = require('./data')
+const checkPass = (query) => {
+ const min = query.split("-")[0]
+ const max = query.split("-")[1].split(" ")[0]
+ const letter = query.split(" ")[1].split(":")[0]
+ const pass = query.split(" ")[2]
+ const amount = (pass.match(new RegExp(letter, "g")) || []).length
+
+ return amount >= min && amount <= max
+}
+
+let valid = 0
+data.forEach(q => checkPass(q) && (valid += 1))
+console.log(valid)