Much cleaner
This commit is contained in:
parent
5dff9ca114
commit
5e3516a64a
|
@ -104,22 +104,13 @@ class Passport {
|
|||
assert.ok(isInRange(parseInt(valid.eyr, 10), 2020, 2030));
|
||||
assert.match(valid.hcl, /^#[0-9a-f]{6}$/);
|
||||
assert.match(valid.pid, /^\d{9}$/);
|
||||
assert.ok([
|
||||
'amb', 'blu', 'brn', 'gry', 'grn', 'hzl', 'oth'
|
||||
].includes(valid.ecl));
|
||||
assert.match(valid.ecl, /^(amb|blu|brn|gry|grn|hzl|oth)$/);
|
||||
assert.match(valid.hgt, /(\d+)(cm|in)/);
|
||||
|
||||
let height = valid.hgt.match(/(\d+)(cm|in)/);
|
||||
if (height) {
|
||||
if (height[2] === 'cm') {
|
||||
assert.ok(isInRange(parseInt(height[1], 10), 150, 193));
|
||||
} else if (height[2] === 'in') {
|
||||
assert.ok(isInRange(parseInt(height[1], 10), 59, 76));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
let [_, measure, unit] = valid.hgt.match(/(\d+)(cm|in)/) as [string, string, string];
|
||||
(unit === 'cm')
|
||||
? assert.ok(isInRange(parseInt(measure, 10), 150, 193))
|
||||
: assert.ok(isInRange(parseInt(measure, 10), 59, 76));
|
||||
} catch (_ignore) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue