I’m just wondering how far we are going with this? — there are a lot of numbers out there. Are there more common patterns?
When you say 823.[2-3] XX → 823.9
do you mean 823.2 XX → 823.2
or 823.3 XX → 823.3
. Where is the 9 coming from?
As a start I am thinking along the lines of the following
const excludedRegions = [
{
rangeRx: /823\.[2-4]/,
excluded: [ 'ZA', 'SL' ]
},
{
rangeRx: /823\.[2-3]/,
excluded: [ 'NZ', 'ET', 'GH', 'KE', 'NG', 'SO', 'ZW', 'ER', 'AO', 'MW', 'LS' ]
},
{
rangeRx: /823\.[3-4]/,
excluded: [ 'AU', 'IN', 'LK', 'PK', 'SG' ]
},
{
rangeRx: /843\.[2-4]/,
excluded: [ 'ML', 'CG', 'CG', 'CH', 'CI', 'CM' /* ...rest here */, 'BU' ]
}
]
const regionExcluded = (num, region) => {
for (const { rangeRx, excluded } of excludedRegions) {
// does the number match the regex range and are the letters excluded
if (rangeRx.test(String(num)) && excluded.includes(region)) {
// is excluded
return true
}
}
// not excluded
return false
}
const testCodes = [
['823.2', 'NZ'],
['823.3', 'KE'],
['823.2', 'CH'],
['843.3', 'CI'],
['843.3', 'ZW'],
]
// check console!
testCodes.forEach(
([num, region]) => {
console.log(
`${num} ${region}: ${regionExcluded(num, region) ? num : `${num} ${region}`}`,
)
}
)
Output:
823.2 NZ: 823.2
823.3 KE: 823.3
823.2 CH: 823.2 CH
843.3 CI: 843.3
843.3 ZW: 843.3 ZW