From d25ded2cf848c66a3885ba6b4932ddabbb44b44a Mon Sep 17 00:00:00 2001 From: ivensgustavo <gustavo_ivens@alu.ufc.br> Date: Sun, 4 Apr 2021 16:29:27 -0300 Subject: [PATCH 1/3] Added condition for negative power values --- src/algorithms/math/fast-powering/fastPowering.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/algorithms/math/fast-powering/fastPowering.js b/src/algorithms/math/fast-powering/fastPowering.js index 4f4a6b3571..b2fa4b7bb6 100644 --- a/src/algorithms/math/fast-powering/fastPowering.js +++ b/src/algorithms/math/fast-powering/fastPowering.js @@ -14,6 +14,13 @@ export default function fastPowering(base, power) { return 1; } + if (power < 0) { + //if power is negative, then powerNext must be inverted + const powerNext = power * -1; + const baseNext = 1 / base; + return fastPowering(baseNext, powerNext); + } + if (power % 2 === 0) { // If the power is even... // we may recursively redefine the result via twice smaller powers: From fdca01990649d6e814b12b1d937609d494cbc559 Mon Sep 17 00:00:00 2001 From: ivensgustavo <gustavo_ivens@alu.ufc.br> Date: Sun, 4 Apr 2021 16:30:58 -0300 Subject: [PATCH 2/3] Added tests for negative power values --- .../math/fast-powering/__test__/fastPowering.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/algorithms/math/fast-powering/__test__/fastPowering.test.js b/src/algorithms/math/fast-powering/__test__/fastPowering.test.js index 0a5da7561a..ae8683dff2 100644 --- a/src/algorithms/math/fast-powering/__test__/fastPowering.test.js +++ b/src/algorithms/math/fast-powering/__test__/fastPowering.test.js @@ -19,5 +19,8 @@ describe('fastPowering', () => { expect(fastPowering(16, 16)).toBe(18446744073709552000); expect(fastPowering(7, 21)).toBe(558545864083284000); expect(fastPowering(100, 9)).toBe(1000000000000000000); + expect(fastPowering(5, -5)).toBe(0.0003200000000000002); + expect(fastPowering(-5, 5)).toBe(-3125); + expect(fastPowering(-5, -5)).toBe(-0.0003200000000000002); }); }); From 628a916595e008e31a6ccf7bb7a9ce0429855ae8 Mon Sep 17 00:00:00 2001 From: ivensgustavo <gustavo_ivens@alu.ufc.br> Date: Tue, 6 Apr 2021 18:00:12 -0300 Subject: [PATCH 3/3] Fixing eslint error --- .eslintrc | 21 +++++++++++++++++-- package.json | 3 ++- .../math/fast-powering/fastPowering.js | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.eslintrc b/.eslintrc index 076399682c..fef9c15cc5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,23 @@ { "root": true, - "extends": "airbnb", - "plugins": ["jest"], + "extends": ["airbnb", "plugin:markdown/recommended"], + "plugins": ["jest", "markdown"], + "overrides": [ + { + // 2. Enable the Markdown processor for all .md files. + "files": ["**/*.md"], + "processor": "markdown/markdown" + }, + { + // 3. Optionally, customize the configuration ESLint uses for ```js + // fenced code blocks inside .md files. + "files": ["**/*.md/*.js"], + // ... + "rules": { + // ... + } + } +], "env": { "jest/globals": true }, @@ -12,4 +28,5 @@ "arrow-body-style": "off", "no-loop-func": "off" } + } diff --git a/package.json b/package.json index 73da04e0cf..9a551b28aa 100644 --- a/package.json +++ b/package.json @@ -37,11 +37,12 @@ "@babel/cli": "7.12.10", "@babel/preset-env": "7.12.11", "@types/jest": "26.0.19", - "eslint": "7.16.0", + "eslint": "^7.16.0", "eslint-config-airbnb": "18.2.1", "eslint-plugin-import": "2.22.1", "eslint-plugin-jest": "24.1.3", "eslint-plugin-jsx-a11y": "6.4.1", + "eslint-plugin-markdown": "^2.0.1", "eslint-plugin-react": "7.21.5", "husky": "4.3.6", "jest": "26.6.3" diff --git a/src/algorithms/math/fast-powering/fastPowering.js b/src/algorithms/math/fast-powering/fastPowering.js index b2fa4b7bb6..8190783e0b 100644 --- a/src/algorithms/math/fast-powering/fastPowering.js +++ b/src/algorithms/math/fast-powering/fastPowering.js @@ -15,7 +15,7 @@ export default function fastPowering(base, power) { } if (power < 0) { - //if power is negative, then powerNext must be inverted + // if power is negative, then powerNext must be inverted const powerNext = power * -1; const baseNext = 1 / base; return fastPowering(baseNext, powerNext);