answer_2 = {
const input = input2;
let valid = 0,
invalid = 0;
let filtered_valid = [];
let filtered_invalid = [];
const pushInvalid = passport => {
invalid++;
filtered_invalid.push(passport);
};
const pushValid = passport => {
valid++;
filtered_valid.push(passport);
};
const correctECL = ["amb", "blu", "brn", "gry", "grn", "hzl", "oth"];
const correctHCL = /#[0-9a-fAF]{6}/;
const correctPID = /[0-9]{9}/;
for (const [passport, fields] of input) {
let byr = +passport.byr;
byr =
passport.byr.length === 4 && byr >= 1920 && byr <= 2002 ? true : false;
let iyr = +passport.iyr;
iyr =
passport.iyr.length === 4 && iyr >= 2010 && iyr <= 2020 ? true : false;
let eyr = +passport.eyr;
eyr =
passport.eyr.length === 4 && eyr >= 2020 && eyr <= 2030 ? true : false;
let hgt = false;
if (passport.hgt.endsWith("cm")) {
hgt = +passport.hgt.slice(0, Math.max(0, passport.hgt.length - 2));
hgt = hgt >= 150 && hgt <= 193 ? true : false;
} else if (passport.hgt.endsWith("in")) {
hgt = +passport.hgt.slice(0, Math.max(0, passport.hgt.length - 2));
hgt = hgt >= 59 && hgt <= 76 ? true : false;
} else hgt = false;
const hcl = correctHCL.test(passport.hcl);
const ecl = correctECL.includes(passport.ecl);
const pid = passport.pid.length === 9 && correctPID.test(passport.pid);
if (!byr || !iyr || !eyr || !hgt || !hcl || !ecl || !pid || false) {
pushInvalid(passport);
} else {
pushValid(passport);
}
}
return { filtered_valid, filtered_invalid };
}