I am currently working on finding the power of a number, specifically 11
to the power of n
. While JavaScript has the built-in function Math.pow
, I have created my own function that works perfectly. However, it has a time complexity of O(n). Is there a way to reduce this time complexity using a different method?
I have considered using a bit map
but have not been successful in implementing it.
function power(x,n) {
let sum = 1
for(let i = 0; i < n; i++){
sum *= x
}
return sum
}
console.log(power(11,3))