1
 How to calculate when using fraction exponent without using Math.pow? Thanks for answering:) 
<code>
    function power(base, exponent) {
      if (exponent === 0) {
        return 1;
      } else if (base === 1) {
        return base;
      } else if (exponent % 1 == 0 && exponent > 0) {
        return base * power(base, exponent - 1); 
      } else if (exponent % 1 !== 0) {
     
      } else {
        return (1 / base) * (1 / power(1 / base, exponent + 1));
      }
    }

</code>
  • 1
    Does this answer your question? [The most efficient way to implement an integer based power function pow(int, int)](https://stackoverflow.com/questions/101439/the-most-efficient-way-to-implement-an-integer-based-power-function-powint-int) – DecPK Nov 02 '21 at 11:57
  • @decpk no. Notheng about fraction exponent there.... – Anna Fridman Nov 02 '21 at 12:30
  • It would be hard to find generic implementation of fraction exponent that will work for all fractions. – DecPK Nov 02 '21 at 12:47
  • @decpk based on your experience, when an interviewer asks to implement this kind of function, should what i wrote be enough? (without the else if (exponent % 1 !== 0) part) – Anna Fridman Nov 02 '21 at 13:07

0 Answers0