var phaseOne = [
{
streetNumberLow: "1",
streetNumberHigh: "436",
streetName: "barnhart",
streetCode: "rd",
city: "waynesburo",
state: "va",
zipCode: "22980",
}
];
var phaseOneExt = [
{
streetNumberLow: "580",
streetNumberHigh: "1002",
streetName: "battlefield",
streetCode: "rd",
city: "fort defiance",
state: "va",
zipCode: "24437",
}
];
var phaseTwo = [
{
streetNumberLow: "1",
streetNumberHigh: "727",
streetName: "bailey",
streetCode: "rd",
city: "fort defiance",
state: "va",
zipCode: "24437",
}
];
var phaseTwoCares = [
{
streetNumberLow: "728",
streetNumberHigh: "996",
streetName: "bailey",
streetCode: "rd",
city: "fort defiance",
state: "va",
zipCode: "24437",
}
];
function parseAddressString(str) {
var matches = str.match(
/(?<streetNumber>\d+)\s+(?<streetName>[\w\s-]+)\s+(?<streetCode>\w+),?\s+(?<city>[\w\s-]+),?\s+(?<state>\w+),?\s+(?<zipCode>\d+)/
);
if (matches) {
return matches.groups;
}
return false;
}
function doesStringMatch(a, b) {
return a.toLowerCase().includes(b.toLowerCase());
}
function doesAddressMatchPhase(address, phase) {
return (
address &&
+address.streetNumber >= +phase.streetNumberLow &&
+address.streetNumber <= +phase.streetNumberHigh &&
doesStringMatch(address.streetName, phase.streetName) &&
doesStringMatch(address.streetCode, phase.streetCode) &&
doesStringMatch(address.city, phase.city) &&
doesStringMatch(address.state, phase.state) &&
doesStringMatch(address.zipCode, phase.zipCode)
);
}
我目前正在构建一个 JavaScript 工具,它将地址作为输入,并将其与服务区域内的临时地址数据库进行比较。我使用 array.some() 方法循环访问服务区域的每个相数组中的每个对象属性。如果前一个阶段返回 false,我还需要它来查看每个阶段。因为我使用 for 循环来循环遍历每个相位数组,所以 .some 方法中所需的返回会导致我的函数在第一个循环中退出。问题出在 isEligible(str) 函数内。附加的代码片段中是损坏的代码。如果我将 return 放在函数的最后两行前面,我可以让它工作,但如果在第一阶段内找不到地址,它不会让循环继续。
至尊宝的传说
相关分类