Wheemangga

JS Plain Math.pow()

Jan 16th, 2025
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.24 KB | Software | 0 0
  1. // Case if aren't allowed to use Math.pow() :
  2.  
  3. const pow = (num, times) => {
  4.   let total = 1
  5.   for (let i=0; i < times; i++) {
  6.     total *= num
  7.   }
  8.   return total
  9. }
  10.  
  11. // console.log(pow(<arg>, <raise>))
  12. console.log(pow(3, 8)) // 8*8*8 = 512
Advertisement
Add Comment
Please, Sign In to add comment