Created
March 22, 2012 11:24
-
-
Save mk270/2157767 to your computer and use it in GitHub Desktop.
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
tax_payable = (band_info, gross) -> | |
tax_in_band = (band) -> | |
band.rate * (Math.min(band.max, gross) - Math.min(band.min, gross)) | |
total = 0 | |
bands = for band in band_info | |
prev_total = total | |
total += band.width + 0 | |
{ width: band.width, rate: band.rate, min: prev_total, max: total } | |
(bands.map tax_in_band).reduce (a, b) -> a + b |
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
var bands = [ | |
{ | |
width: 10000, | |
rate: 0.0 | |
}, | |
{ | |
width: 10000, | |
rate: 0.1 | |
}, | |
{ | |
width: 20000, | |
rate: 0.2 | |
}, | |
{ | |
width: 110000, | |
rate: 0.4 | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment