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/__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); }); }); diff --git a/src/algorithms/math/fast-powering/fastPowering.js b/src/algorithms/math/fast-powering/fastPowering.js index 4f4a6b3571..8190783e0b 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: