From: Scott Worley Date: Thu, 23 May 2019 21:37:46 +0000 (-0700) Subject: Handle the fully-deductible case X-Git-Tag: v1.0~13 X-Git-Url: http://git.scottworley.com/inverse-tax/commitdiff_plain/49188cbe174f6f0559037bb2f6e51300dac90a85?ds=inline Handle the fully-deductible case --- diff --git a/tax.js b/tax.js index 7f32f74..d9bd34c 100644 --- a/tax.js +++ b/tax.js @@ -53,8 +53,6 @@ function merge_tax_tables(t1, t2) { } function invert(table) { - if (table.length == 0) return x => x; - // Here we solve // net = m * gross + b // for gross: @@ -90,5 +88,6 @@ function invert(table) { return (net - b) / m; } } + return net; }; } diff --git a/tax.test.js b/tax.test.js index 14c48c0..125cc20 100644 --- a/tax.test.js +++ b/tax.test.js @@ -57,5 +57,6 @@ test("invert", () => { assert.strictEqual(invert([ ])(10), 10); assert.strictEqual(invert([[ 0, Infinity, .1]])( 9), 10); assert.strictEqual(invert([[10, Infinity, .1]])(19), 20); + assert.strictEqual(invert([[10, Infinity, .1]])( 9), 9); assert.strictEqual(invert([[0, 100, .1], [100, Infinity, .2]])(170), 200); });