Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: trekhleb/javascript-algorithms
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: nikikalwar/javascript-algorithms
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: my-test
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 16 commits
  • 2 files changed
  • 4 contributors

Commits on Dec 15, 2020

  1. Copy the full SHA
    4eb5703 View commit details
  2. Copy the full SHA
    aad1011 View commit details

Commits on Dec 16, 2020

  1. Copy the full SHA
    e076e12 View commit details
  2. Copy the full SHA
    c82ceab View commit details
  3. Copy the full SHA
    0cb77d0 View commit details
  4. Copy the full SHA
    a64c587 View commit details

Commits on Dec 17, 2020

  1. fixed:error

    nikikalwar committed Dec 17, 2020
    Copy the full SHA
    3b1fcd8 View commit details
  2. Copy the full SHA
    506aefb View commit details
  3. Copy the full SHA
    5ed34c7 View commit details

Commits on Dec 18, 2020

  1. Copy the full SHA
    5daae15 View commit details

Commits on Feb 6, 2021

  1. Copy the full SHA
    b3da0ab View commit details

Commits on Jun 18, 2021

  1. Copy the full SHA
    f7bb28a View commit details
  2. Copy the full SHA
    43b806f View commit details

Commits on Jun 23, 2021

  1. edited the comments

    Niki.kalwar committed Jun 23, 2021
    Copy the full SHA
    604e9cd View commit details
  2. Update fastPowering.js

    nikikalwar authored Jun 23, 2021
    Copy the full SHA
    2c22198 View commit details
  3. Copy the full SHA
    310343e View commit details
Showing with 9 additions and 0 deletions.
  1. +3 −0 src/algorithms/math/fast-powering/__test__/fastPowering.test.js
  2. +6 −0 src/algorithms/math/fast-powering/fastPowering.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
6 changes: 6 additions & 0 deletions src/algorithms/math/fast-powering/fastPowering.js
Original file line number Diff line number Diff line change
@@ -14,6 +14,12 @@ export default function fastPowering(base, power) {
return 1;
}

if (power < 0) {
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: