mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
Update Binary Exponentiation algorithm file to comply with Javascript standard rules
This commit is contained in:
@@ -12,13 +12,13 @@
|
||||
// = exponent(x*x, floor(n/2)) ; if n is odd
|
||||
// = x*exponent(x*x, floor(n/2)) ; if n is even
|
||||
const exponent = (x, n) => {
|
||||
let ans = 1
|
||||
while(n > 0) {
|
||||
if(n%2 != 0) ans *= x
|
||||
n = Math.floor(n/2)
|
||||
if(n > 0) x *= x
|
||||
}
|
||||
return ans
|
||||
let ans = 1
|
||||
while (n > 0) {
|
||||
if (n % 2 !== 0) ans *= x
|
||||
n = Math.floor(n / 2)
|
||||
if (n > 0) x *= x
|
||||
}
|
||||
return ans
|
||||
}
|
||||
|
||||
export { exponent }
|
||||
export { exponent }
|
||||
|
||||
Reference in New Issue
Block a user