Skip to content

Instantly share code, notes, and snippets.

@jish
Created October 13, 2012 00:31
Show Gist options
  • Select an option

  • Save jish/3882579 to your computer and use it in GitHub Desktop.

Select an option

Save jish/3882579 to your computer and use it in GitHub Desktop.
def tax_brackets(salary)
current = salary
total = 0
if salary > 8_700
total += 8_700 * 0.10
else
return salary * 0.10
end
if salary > 35_550
total += (35_550 - 8_700) * 0.15
else
return total + (salary - 8_700) * 0.15
end
if salary > 85_650
total += (85_650 - 35_550) * 0.25
else
return total + (salary - 35_550) * 0.25
end
if salary > 178_650
total += (178_650 - 85_650) * 0.28
else
return total + (salary - 85_650) * 0.28
end
end
def percentage(salary)
tax = tax_brackets(salary)
tax.to_f / salary * 100
end
puts tax_brackets(5000) # 500.0
puts tax_brackets(10_000) # 1065.0
puts tax_brackets(100_000) # 21440.5
puts percentage(100_000) # 21.4405
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment