aoc/2020/04/part1.js

18 lines
449 B
JavaScript
Raw Permalink Normal View History

2020-12-04 18:46:17 +00:00
const fs = require('fs');
const data = fs.readFileSync('input.txt', 'utf-8');
const passports = data.split('\n\n').map(p=>p.split(/[\n\s]/g).map(e=>e.split(":")));
// requried fields
const req = ['ecl', 'eyr', 'hcl', 'byr', 'iyr', 'pid', 'hgt'];
let validamt = 0
passports.forEach(passport=>{
for(let i = 0; i < req.length; i++){
if(!passport.find(entry => entry[0] == req[i])){
return
}
}
validamt++
});
console.log(validamt)