Skip to content

Instantly share code, notes, and snippets.

@anatomic
Created December 4, 2014 21:16
Show Gist options
  • Save anatomic/8cbe5b0f0ad4227a99fe to your computer and use it in GitHub Desktop.
Save anatomic/8cbe5b0f0ad4227a99fe to your computer and use it in GitHub Desktop.
Stamp Duty Calculator
var range = {
0: { min: 0, max: 125000},
2: { min: 125000, max: 250000},
5: { min: 250000, max: 925000},
10: { min: 925000, max: 1500000},
12: { min: 1500000, max: null}
};
function stampDuty(houseValue) {
return Object.keys(range).reduce(function(duty, percentage) {
var r = range[percentage];
var rangeVal = 0;
if (houseValue < r.min) {
return duty;
}
if ((houseValue > r.min && houseValue <= r.max) || r.max === null ) {
rangeVal = houseValue - r.min;
} else if (houseValue > r.max) {
rangeVal = r.max - r.min;
}
return duty += rangeVal * (percentage / 100);;
}, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment