Created
February 1, 2012 04:06
-
-
Save bwilkins/1715027 to your computer and use it in GitHub Desktop.
Hopefully faster/better version of previous tax function
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
function tax(total) { | |
var accum = 0; | |
var tiers = [ | |
0, | |
14000, | |
48000, | |
70000, | |
] | |
if (total <= tiers[1]) | |
return total*0.1254 | |
accum += tiers[1]*0.1254 | |
total -= tiers[1] | |
var accumtier2 = tiers[2]-tiers[1] | |
if (total <= accumtier2) | |
return accum + total*0.1954 | |
accum += accumtier2*0.1954 | |
total -= accumtier2 | |
var accumtier3 = tiers[3]-accumtier2 | |
if (total <= accumtier3) | |
return accum + total*0.3204 | |
accum += accumtier3*0.3204 | |
total -= accumtier3 | |
accum += total*0.3504 | |
return accum | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment