From 8048786ed3c75a8251a784afc61cfc541821ba6f Mon Sep 17 00:00:00 2001 From: Cristian Baciu Date: Mon, 19 Oct 2020 14:50:06 +0300 Subject: [PATCH 1/2] Add pow.js --- Maths/Pow.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Maths/Pow.js diff --git a/Maths/Pow.js b/Maths/Pow.js new file mode 100644 index 0000000000..555e652aa6 --- /dev/null +++ b/Maths/Pow.js @@ -0,0 +1,11 @@ +// Returns the value of x to the power of y + +const pow = (x, y) => { + let result = 1 + for (let i = 1; i <= y; i++) { + result *= x + } + return result +} + +export { pow } From d801a751391e0759aaa19d94687fc1617bd6dde2 Mon Sep 17 00:00:00 2001 From: Cristian Baciu Date: Mon, 19 Oct 2020 15:47:39 +0300 Subject: [PATCH 2/2] Add tests for Pow.js --- Maths/test/Pow.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Maths/test/Pow.test.js diff --git a/Maths/test/Pow.test.js b/Maths/test/Pow.test.js new file mode 100644 index 0000000000..f5760048eb --- /dev/null +++ b/Maths/test/Pow.test.js @@ -0,0 +1,15 @@ +import { pow } from '../Pow' + +describe('Pow', () => { + it('should return 1 for numbers with exponent 0', () => { + expect(pow(2, 0)).toBe(1) + }) + + it('should return 0 for numbers with base 0', () => { + expect(pow(0, 23)).toBe(0) + }) + + it('should return the base to the exponent power', () => { + expect(pow(24, 4)).toBe(331776) + }) +})