javascript-algorithms
javascript-algorithms copied to clipboard
added the condition to handle negative integers for fastPowering algorithm.
Issue:
Error:RangeError: Maximum call stack size exceeded #590
I have edited the fastpowering algorithm to handle negative integers and the test file to check the negative integers condition.
How about checking for power equals 1, this can avoid from calculate fastPowering(base, 1) = fastPowering(base, 0) * fastPowering(base, 0) * base everytimes.
if (power === 0) {
// Anything that is raised to the power of zero is 1.
return 1;
}
if (power === 1) {
return base;
}
.
.
.