Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
Comprobar que un número en una matriz es un número de potencias

¿Cómo verificar qué número es una potencia en esta matriz? arr = [16, 32, 72, 96]

salida: [16, 32] porque 16 = 4^2 y 32 = 2^5

No es una solución sobre la potencia de 2, se trata de la potencia de n.

Este es mi código real:

 let array1 = [16, 32, 72]; function findPowofNum(array1) { // var result = []; if (array1.length == 1) return true; for(let i = 2; i * i <= array1.length; i++) { let value = Math.log(array1/length) / Math.log(i); if((value - Math.floor(value)) < 0.00000001) return true; } return false; } console.log(findPowofNum(array1));

¿Me puede dar un ejemplo para esta solución por javascript?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Qué tal si

 arr = [16, 32, 72, 96].filter( value => Number.isInteger(Math.log2(value)) )
about 4 years ago · Juan Pablo Isaza Report

0

const numbers = [16, 32, 72, 96]; const power = numbers.filter(isPowerOfTwo); function isPowerOfTwo(n) { if (n == 0) return 0; while (n != 1) { if (n%2 != 0) return 0; n = n/2; } return 1; } console.log(power);

Para saber más sobre esta visita, visite: https://www.geeksforgeeks.org/program-to-find-whether-a-given-number-is-power-of-2/

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar una función booleana personalizada para iterar a través de los elementos y agregarlos a una matriz vacía mientras verifica de esta manera ...

 function isPowerofTwo(n){ return (Math.ceil((Math.log(n) / Math.log(2)))) == (Math.floor(((Math.log(n) / Math.log(2))))); } let arr= [16, 32, 72, 96]; let values=[] for(let i=0;i<arr.length;i++){ if(isPowerofTwo(arr[i])){ values.push(arr[i]); } } console.log(values);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!