Created
August 7, 2014 13:45
-
-
Save zerob13/20f752f7d147dd35d382 to your computer and use it in GitHub Desktop.
the powering ladder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myPower(x, n) { | |
var y = 1; | |
while (1) { | |
t = n % 2; | |
n = Math.floor(n / 2); | |
if (t == 1) { | |
y = y * x; | |
} | |
if (n == 0) { | |
break; | |
} | |
x = x * x; | |
} | |
return y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment