JSFiddle - React, Tailwind, and code Playground
JavaScript
function power(x,y){
if(y==0) return 1;
let result = x;
while(y > 1){
result = result*x;
y--;
}
return result;
}
function power2(x,y){
if(y==0) return 1;
let result = x;
while(y / 2 > 1){
result = result*x;
y--;
}
return result*result;
}
function powerSimplified(x,y){
if(y==0) return 1;
return x*(y-1);
}
console.log("result is",powerSimplified(3,4));