[Algorithm] Write your own Math.pow function in Javascript, using Recursive approach

/**@abstract
* Write your own Math.pow(a int, b int) function
* */ function pow (a, b) { let result = ;
let nigate = b < ;
b = nigate ? b*(-) : b;
if (b === ) {
result = ;
} let isEven = b % === ; if (b === ) {
result = a;
} if (b >= ) {
result = isEven ? pow(a, b / ) * pow(a, b / ) : a * pow(a, b-);
} return nigate ? / result : result;
} console.log(pow(, ) === Math.pow(,));
console.log(pow(, -) === Math.pow(, -));
console.log(pow(, ) === Math.pow(, ));
console.log(pow(, ) === Math.pow(, ));
console.log(pow(, ) === Math.pow(, ));
console.log(pow(-, ) === Math.pow(-, ));
console.log(pow(-, -) === Math.pow(-, -));
console.log(pow(, ) === Math.pow(,));
console.log(pow(, -) === Math.pow(, -));
console.log(pow(, ) === Math.pow(,));
console.log(pow(, -) === Math.pow(, -));
console.log(pow(-, ) === Math.pow(-, ));
console.log(pow(, ) === Math.pow(, ));
上一篇:c# 实现ListView的排序


下一篇:【ASP.NET Core分布式项目实战】(三)整理IdentityServer4 MVC授权、Consent功能实现