Skip to content

Instantly share code, notes, and snippets.

@sagar290
Created June 17, 2023 08:16
Show Gist options
  • Save sagar290/d18f4b402574f1ae046aa39165220108 to your computer and use it in GitHub Desktop.
Save sagar290/d18f4b402574f1ae046aa39165220108 to your computer and use it in GitHub Desktop.
function power(base, exponent) {
let result = 1;
for (let i = 0; i < Math.floor(exponent); i++) {
result *= base;
}
if (exponent % 1 !== 0) {
result *= base ** (exponent % 1);
}
return result;
}
const base = 2;
const exponent = 2.5;
const result = power(base, exponent);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment