Skip to content

Latest commit

 

History

History
14 lines (13 loc) · 243 Bytes

powx-n.md

File metadata and controls

14 lines (13 loc) · 243 Bytes
/**
 * @param {number} x
 * @param {number} n
 * @return {number}
 */
var myPow = function(x, n) {
    if(n == 0) return 1;
    if(n < 0) return 1/myPow(x,-n);
    if(n%2) return x*myPow(x,n-1);
    return myPow(x*x,n/2);
};