Skip to content

Instantly share code, notes, and snippets.

@HubSpotHanevold
Created June 25, 2025 17:27
Show Gist options
  • Save HubSpotHanevold/d8ffc4aa0c8f7aca3d11d585056c781f to your computer and use it in GitHub Desktop.
Save HubSpotHanevold/d8ffc4aa0c8f7aca3d11d585056c781f to your computer and use it in GitHub Desktop.
exports.main = async (event, callback) => {
let state_zips = [
{ "state": "AL", "zip_low": 35004, "zip_high": 36925 },
{ "state": "AK", "zip_low": 99501, "zip_high": 99950 },
{ "state": "AZ", "zip_low": 85001, "zip_high": 86556 },
{ "state": "AR", "zip_low": 71601, "zip_high": 72959 },
{ "state": "CA", "zip_low": 90001, "zip_high": 96162 },
{ "state": "CO", "zip_low": 80001, "zip_high": 81658 },
{ "state": "CT", "zip_low": 6001, "zip_high": 6928 },
{ "state": "DE", "zip_low": 19701, "zip_high": 19980 },
{ "state": "FL", "zip_low": 32003, "zip_high": 34997 },
{ "state": "GA", "zip_low": 30002, "zip_high": 39901 },
{ "state": "HI", "zip_low": 96701, "zip_high": 96898 },
{ "state": "ID", "zip_low": 83201, "zip_high": 83877 },
{ "state": "IL", "zip_low": 60001, "zip_high": 62999 },
{ "state": "IN", "zip_low": 46001, "zip_high": 47997 },
{ "state": "IA", "zip_low": 50001, "zip_high": 52809 },
{ "state": "KS", "zip_low": 66002, "zip_high": 67954 },
{ "state": "KY", "zip_low": 40003, "zip_high": 42788 },
{ "state": "LA", "zip_low": 70001, "zip_high": 71497 },
{ "state": "ME", "zip_low": 3901, "zip_high": 4992 },
{ "state": "MD", "zip_low": 20588, "zip_high": 21930 },
{ "state": "MA", "zip_low": 1001, "zip_high": 5544 },
{ "state": "MI", "zip_low": 48001, "zip_high": 49971 },
{ "state": "MN", "zip_low": 55001, "zip_high": 56763 },
{ "state": "MS", "zip_low": 38601, "zip_high": 39776 },
{ "state": "MO", "zip_low": 63001, "zip_high": 65899 },
{ "state": "MT", "zip_low": 59001, "zip_high": 59937 },
{ "state": "NE", "zip_low": 68001, "zip_high": 69367 },
{ "state": "NV", "zip_low": 88901, "zip_high": 89883 },
{ "state": "NH", "zip_low": 3031, "zip_high": 3897 },
{ "state": "NJ", "zip_low": 7001, "zip_high": 8989 },
{ "state": "NM", "zip_low": 87001, "zip_high": 88439 },
{ "state": "NY", "zip_low": 501, "zip_high": 14925 },
{ "state": "NC", "zip_low": 27006, "zip_high": 28909 },
{ "state": "ND", "zip_low": 58001, "zip_high": 58856 },
{ "state": "OH", "zip_low": 43001, "zip_high": 45999 },
{ "state": "OK", "zip_low": 73001, "zip_high": 74966 },
{ "state": "OR", "zip_low": 97001, "zip_high": 97920 },
{ "state": "PA", "zip_low": 15001, "zip_high": 19640 },
{ "state": "RI", "zip_low": 2801, "zip_high": 2940 },
{ "state": "SC", "zip_low": 29001, "zip_high": 29945 },
{ "state": "SD", "zip_low": 57001, "zip_high": 57799 },
{ "state": "TN", "zip_low": 37010, "zip_high": 38589 },
{ "state": "TX", "zip_low": 73301, "zip_high": 88595 },
{ "state": "UT", "zip_low": 84001, "zip_high": 84791 },
{ "state": "VT", "zip_low": 5001, "zip_high": 5907 },
{ "state": "VA", "zip_low": 20101, "zip_high": 24658 },
{ "state": "WA", "zip_low": 98001, "zip_high": 99403 },
{ "state": "WV", "zip_low": 24701, "zip_high": 26886 },
{ "state": "WI", "zip_low": 53001, "zip_high": 54990 },
{ "state": "WY", "zip_low": 82001, "zip_high": 83414 }
];
const zip = event.inputFields['zip'];
const input_state = event.inputFields['state'];
// Function to find the state by zip
function findStateByZip(zip) {
const stateEntry = state_zips.find(entry => zip >= entry.zip_low && zip <= entry.zip_high);
return stateEntry ? stateEntry.state : null;
}
const output_state = findStateByZip(zip);
console.log('Zip code: ' + zip)
console.log('State on the contact record: ' + input_state);
console.log('State identified by zip code: ' + output_state);
if(input_state == output_state) {
callback({
outputFields: {
states_match: true,
correct_state: 'na'
}
});
} else {
callback({
outputFields: {
states_match: false,
correct_state: output_state
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment