Skip to content

Instantly share code, notes, and snippets.

@mk270
Created March 22, 2012 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mk270/2157767 to your computer and use it in GitHub Desktop.
Save mk270/2157767 to your computer and use it in GitHub Desktop.
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
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