Last active
September 12, 2022 01:33
-
-
Save sabatale/14697c9af8ae4e2fa31f2a32548a71d9 to your computer and use it in GitHub Desktop.
Guess the province & sales taxes from any given postal code (Canada)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A very simple example (sales taxes from 2022) | |
function findProvince(input) { | |
// Starting postal code character - https://www150.statcan.gc.ca/n1/pub/92-195-x/2011001/other-autre/pc-cp/tbl/tbl9-eng.htm | |
// Provinces short codes - https://www150.statcan.gc.ca/n1/pub/92-195-x/2011001/geo/prov/tbl/tbl8-eng.htm | |
// Sales taxes by province - https://www.retailcouncil.org/resources/quick-facts/sales-tax-rates-by-province/ | |
//var input = "H2V 1V8"; | |
var postal = input.substring(0, 1).toLowerCase(); // E.g., "H2V 1V8" becomes "h" | |
if (postal == "a") { | |
var province = "NL"; | |
var pst = 0; | |
var gst = 0.15; | |
} else if (postal == "b") { | |
var province = "NS"; | |
var pst = 0; | |
var gst = 0.15; | |
} else if (postal == "c") { | |
var province = "PE"; | |
var pst = 0; | |
var gst = 0.15; | |
} else if (postal == "e") { | |
var province = "NB"; | |
var pst = 0; | |
var gst = 0.15; | |
} else if (postal == "g" || postal == "h" || postal == "j") { | |
var province = "QC"; | |
var pst = 0.09975; | |
var gst = 0.05; | |
} else if (postal == "k" || postal == "l" || postal == "m" || postal == "n" || postal == "p") { | |
var province = "ON"; | |
var pst = 0; | |
var gst = 0.13; | |
} else if (postal == "r") { | |
var province = "MB"; | |
var pst = 0.07; | |
var gst = 0.05; | |
} else if (postal == "s") { | |
var province = "SK"; | |
var pst = 0.06; | |
var gst = 0.05; | |
} else if (postal == "t") { | |
var province = "AB"; | |
var pst = 0; | |
var gst = 0.05; | |
} else if (postal == "v") { | |
var province = "BC"; | |
var pst = 0.07; | |
var gst = 0.05; | |
} else if (postal == "x") { | |
var province = "NT/NU"; | |
var pst = 0; | |
var gst = 0.05; | |
} else if (postal == "y") { | |
var province = "YT"; | |
var pst = 0; | |
var gst = 0.05; | |
} else { | |
var province = postal; | |
var pst = ""; | |
var gst = ""; | |
} | |
return [province, pst, gst]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment