Skip to content

Instantly share code, notes, and snippets.

@thawkin3
Created August 24, 2022 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thawkin3/6930f74c8a57aad4cd50316f21361080 to your computer and use it in GitHub Desktop.
Save thawkin3/6930f74c8a57aad4cd50316f21361080 to your computer and use it in GitHub Desktop.
export const power = (x, y) => {
if (y < 0) {
throw new Error(
'exponent must be greater than or equal to 0 (for the purposes of this example)'
);
}
if (y === 0) {
return 1;
}
return x * power(x, y - 1);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment