Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 354 Bytes

File metadata and controls

16 lines (12 loc) · 354 Bytes

Exercise

Write a function to calculate the exponential of a number.

Solution

const exponential = function(b, n){
  if(n === 0) return 1;
  if(n === 1) return b;
  return b * exponential(b, n - 1);
}

console.assert(exponential(2, 6) === 64, "Wrong implementation");
console.assert(exponential(2, 10) === 1024, "Wrong implementation");