Skip to content

Instantly share code, notes, and snippets.

@matthewblewitt
Last active October 26, 2023 14:52
Show Gist options
  • Save matthewblewitt/d42106da42c69e680c801da84a48d695 to your computer and use it in GitHub Desktop.
Save matthewblewitt/d42106da42c69e680c801da84a48d695 to your computer and use it in GitHub Desktop.
Income tax calc
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