From 1c6e40691d86539d80018aa8fc495272b900c4c4 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 23 May 2019 13:18:39 -0700 Subject: [PATCH] Handle empty tax table --- tax.js | 2 ++ tax.test.js | 1 + 2 files changed, 3 insertions(+) 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); -- 2.44.1