Skip to content

Instantly share code, notes, and snippets.

@Samuelachema
Created August 14, 2018 00:21
Show Gist options
  • Save Samuelachema/0eac832224ed7acf6d3c7ee0a72359d4 to your computer and use it in GitHub Desktop.
Save Samuelachema/0eac832224ed7acf6d3c7ee0a72359d4 to your computer and use it in GitHub Desktop.
Write a function named power that accepts two arguments, a and b and calculates a raised to the power b
/*Write a function named power that accepts two arguments, a and b and calculates a raised to the power b.
Example
power(2, 3) => 8
Note: Don't use
2 ** 3
and don't use
Math.pow(2, 3)
*/
function power(a,b){
return b--?a*power(a,b):1;
}
@opeeny
Copy link

opeeny commented Sep 9, 2019

b--?a*power(a,b):1;, someone explain this line of code..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment