Skip to content

Commit

Permalink
Update PowerExponent.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
godwinjs authored Jan 16, 2025
1 parent 44ea527 commit 25df687
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions PowerExponent.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function Power (base: num, exp: number): number {

if(exp <= 0){
if(exp <= 0){//base case
return 1
}

return base * Power(base, exp - 1)
return base * Power(base, exp - 1) // reducing the exponent on each call till you hit the base case, then you multiply the first base var by the results gotten when function is unwinding
}

console.log( Power(2, 3) ) // 8
Expand Down

0 comments on commit 25df687

Please sign in to comment.