/**@abstract * Write your own Math.pow(a int, b int) function * */ function pow (a, b) { let result = 0; let nigate = b < 0; b = nigate ? b*(-1) : b; if (b === 0) { result = 1; } let isEven = b % 2 === 0; if (b === 1) { result = a; } if (b >= 2) { result = isEven ? pow(a, b / 2) * pow(a, b / 2) : a * pow(a, b-1); } return nigate ? 1 / result : result; } console.log(pow(0, 0) === Math.pow(0,0)); console.log(pow(0, -2) === Math.pow(0, -2)); console.log(pow(0, 1) === Math.pow(0, 1)); console.log(pow(0, 2) === Math.pow(0, 2)); console.log(pow(0, 3) === Math.pow(0, 3)); console.log(pow(-4, 3) === Math.pow(-4, 3)); console.log(pow(-4, -3) === Math.pow(-4, -3)); console.log(pow(4, 3) === Math.pow(4,3)); console.log(pow(4, -3) === Math.pow(4, -3)); console.log(pow(4, 2) === Math.pow(4,2)); console.log(pow(4, -2) === Math.pow(4, -2)); console.log(pow(-4, 1) === Math.pow(-4, 1)); console.log(pow(4, 1) === Math.pow(4, 1));