X-Git-Url: http://git.scottworley.com/inverse-tax/blobdiff_plain/1c6e40691d86539d80018aa8fc495272b900c4c4..82b7a49862ffba0bcd9e6b5500b4ed2e901444e8:/tax.js diff --git a/tax.js b/tax.js index d26db5f..7f32f74 100644 --- a/tax.js +++ b/tax.js @@ -7,11 +7,15 @@ function parse_table(as_text) { return as_text.trim().split('\n').map(parse_line); } -function parse_tax_table(as_text) { - return parse_table(as_text).map(([start, rate], i, table) => +function tax_table_from_table(table) { + return table.map(([start, rate], i, table) => [start, i < table.length - 1 ? table[i+1][0] : Infinity, rate / 100.0]); } +function parse_tax_table(as_text) { + return tax_table_from_table(parse_table(as_text)); +} + function sum(nums) { return nums.reduce((total, num) => total + num, 0); }