From 0ed8578dedcf415f8142bfe144597a6e7218070e Mon Sep 17 00:00:00 2001 From: Frederique Mittelstaedt Date: Thu, 7 Mar 2019 14:07:11 +0000 Subject: [PATCH] feat(calculator.ts): add inverse method --- src/Calculator.ts | 5 +++++ tests/Calculator.test.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/Calculator.ts b/src/Calculator.ts index 3c0eb36..0044d72 100644 --- a/src/Calculator.ts +++ b/src/Calculator.ts @@ -71,4 +71,9 @@ export default class Calculator { this.current = Math.tan(this.current); return this; } + + public inverse() { + this.current = div(1, this.current); + return this; + } } diff --git a/tests/Calculator.test.ts b/tests/Calculator.test.ts index 3ad80e3..aa5a1c3 100644 --- a/tests/Calculator.test.ts +++ b/tests/Calculator.test.ts @@ -22,4 +22,6 @@ describe("Calculator", () => { it("can cos", () => expect(calculator.cos().value()).equal(1)); // prettier-ignore it("can tan", () => expect(calculator.clear().tan().value()).equal(0)); + // prettier-ignore + it("can invert", () => expect(calculator.clear().add(2).inverse().value()).equal(1 / 2)); });