Ad
Code
Diff
  • const power = (num, p = 1) => num ** p;
    • function power(num,exp){
    • if(exp === 0){
    • return 1;
    • }
    • if(exp % 2 === 0){
    • let half = Math.floor(exp/2)
    • return power(num, half) * power(num, half);
    • }else{
    • let half = Math.floor((exp-1)/2)
    • return num * power(num, half) * power(num, half);
    • }
    • }
    • const power = (num, p = 1) => num ** p;