Javascript Number Integer power of two

Description

Javascript Number Integer power of two

function PowersofTwo(num) { 
    function divideBy2(n){
    if( n === 2 ){
      return "true";
    }//  w ww.j av  a2 s.  co m
    if ( n < 2 ){
      return "false";
    }
    return divideBy2(n/2);    
  }
  return divideBy2(num);
}

console.log(PowersofTwo(1));



PreviousNext

Related