js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Power of two #472

Closed RazvanBugoi closed 4 years ago

RazvanBugoi commented 4 years ago

https://www.codewars.com/kata/534d0a229345375d520006a0/train/javascript

RazvanBugoi commented 4 years ago
function isPowerOfTwo(n){
  let num = 52;
  let output = [];
    for (let i=0; i<=num; i++) {
      output.push(i);
  }
   let powersOfTwo = output.map((element) => Math.pow(2,element));
    return powersOfTwo.includes(n);
}
RazvanBugoi commented 4 years ago

I am pretty sure this is not the most efficient solution, but couldn't think of anything else at the moment.