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.ok(isInRange(parseInt(valid.eyr, 10), 2020, 2030));
|
||||||
assert.match(valid.hcl, /^#[0-9a-f]{6}$/);
|
assert.match(valid.hcl, /^#[0-9a-f]{6}$/);
|
||||||
assert.match(valid.pid, /^\d{9}$/);
|
assert.match(valid.pid, /^\d{9}$/);
|
||||||
assert.ok([
|
assert.match(valid.ecl, /^(amb|blu|brn|gry|grn|hzl|oth)$/);
|
||||||
'amb', 'blu', 'brn', 'gry', 'grn', 'hzl', 'oth'
|
assert.match(valid.hgt, /(\d+)(cm|in)/);
|
||||||
].includes(valid.ecl));
|
|
||||||
|
|
||||||
let height = valid.hgt.match(/(\d+)(cm|in)/);
|
let [_, measure, unit] = valid.hgt.match(/(\d+)(cm|in)/) as [string, string, string];
|
||||||
if (height) {
|
(unit === 'cm')
|
||||||
if (height[2] === 'cm') {
|
? assert.ok(isInRange(parseInt(measure, 10), 150, 193))
|
||||||
assert.ok(isInRange(parseInt(height[1], 10), 150, 193));
|
: assert.ok(isInRange(parseInt(measure, 10), 59, 76));
|
||||||
} else if (height[2] === 'in') {
|
|
||||||
assert.ok(isInRange(parseInt(height[1], 10), 59, 76));
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (_ignore) {
|
} catch (_ignore) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue