18 lines
449 B
JavaScript
18 lines
449 B
JavaScript
|
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)
|