Last active
October 26, 2023 14:52
-
-
Save matthewblewitt/d42106da42c69e680c801da84a48d695 to your computer and use it in GitHub Desktop.
Income tax calc
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
type Brackets = { | |
min: number; | |
max: number; | |
rate: number; | |
}[]; | |
export const calculateIncomeTax = (salary: number, brackets: Brackets) => { | |
return brackets.reduce<number>((acc, b) => { | |
if (salary > b.min) { | |
const taxableAmount = Math.min(salary, b.max) - b.min; | |
return acc + taxableAmount * b.rate; | |
} | |
return acc; | |
}, 0); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment