Hi all,
I have a Javascript project on where I need to sift through a bunch of 4 digit Aussie post code ranges, and assign a State/Territory depending on the range. For example given the following ranges:
3000 - 3138, 3140 - 3207, 3428, 3752, 3765, 3793, 3796, 3802 - 3806, 3910, 3930/1, 3975 - 3977 = MELBOURNE
4000 - 4179, 4205 - 4207, 4300 - 4305, 4500 - 4503 = BRISBANE
etc etc…
If a user put in one of these, they should be assigned the code “MELBOURNE”, or “BRISBANE” respectively.
Normally I would run the input through a switch, runing a match for each individual range case by case - but with so many postcodes to sift through per state/Territory, the switch would be a mile long in depth!
So Im thinking it would be a good idea to test every range for a given state in a single case (I hope that makes sense!). My question is, is this a good/safe way to do things?
Example:
case (((intPostCode >= 3000) && (intPostCode <= 3138))
||((intPostCode >= 3140) && (intPostCode <= 3207))
||(intPostCode == 3428)
||(intPostCode == 3752)
||(intPostCode == 3765)
||(intPostCode == 3793)
||(intPostCode == 3796)
||((intPostCode >= 3802) && (intPostCode <= 3806))
||(intPostCode == 3910)
||(intPostCode == 3930)
||((intPostCode >= 3975) && (intPostCode <= 3977))
):
myState = “MELBOURNE”;
break;
I know this a bit cumbersome, but with no access to a database, and a low budget, I cannot think of a better idea.