Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Same thing in ruby
Infinity = 1.0/0
SAVINGS_INCOME_TAX_200910 = [[0, 6475], [0.1, 8915], [0.2, 43875], [0.4, Infinity]]
INCOME_TAX_200910 = [[0, 6475], [0.2, 43875], [0.4, Infinity]]
def tax(income, bands=INCOME_TAX_200910)
rate, threshold = bands.first
if income <= threshold
rate * income
else
lowered_remaining_bands = bands[1..-1].map {|r, t| [r, t - threshold]}
rate * threshold + tax(income - threshold, lowered_remaining_bands)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment