From: Scott Worley Date: Thu, 23 May 2019 20:18:39 +0000 (-0700) Subject: Handle empty tax table X-Git-Tag: v1.0~16 X-Git-Url: http://git.scottworley.com/inverse-tax/commitdiff_plain/1c6e40691d86539d80018aa8fc495272b900c4c4?ds=sidebyside Handle empty tax table --- diff --git a/tax.js b/tax.js index 0d94200..d26db5f 100644 --- a/tax.js +++ b/tax.js @@ -49,6 +49,8 @@ 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: diff --git a/tax.test.js b/tax.test.js index 19597fb..48f2e0d 100644 --- a/tax.test.js +++ b/tax.test.js @@ -47,6 +47,7 @@ test("merge tax tables", () => { }); 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([[0, 100, .1], [100, Infinity, .2]])(170), 200);