Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
Number detecting in javascript

So I had visited a lot of websites and still havent found anything on this topic. I want to write a function (in javascript) that checks the output of this code:

function mineHash(length) {
    var result           = '';
    var characters       = '01';
    var charactersLength = characters.length;
    for ( var i = 0; i < length; i++ ) {
      result += characters.charAt(Math.floor(Math.random() * charactersLength));
   }
   return result;
}

console.log(mineHash(256));

and if the output has 70 or more 0s at the start it logs: ("Valid hash found!")

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

We create a string of 70 zeroes and check if the mineHash result starts with these 70 zeroes. I also output the hash so we can check the result.

function mineHash(length) {
    var result           = '';
    var characters       = '01';
    var charactersLength = characters.length;
    for ( var i = 0; i < length; i++ ) {
      result += characters.charAt(Math.floor(Math.random() * charactersLength));
   }
   return result;
}

const manyZeroes = '0'.repeat(70);
const hash = mineHash(256);
console.log(hash)
console.log(hash.startsWith(manyZeroes) ? 'Valid hash found!' : 'NOT a valid hash!')

// or an alternative suggested by Peter B:
console.log(/^0{70}/.test(hash) ? 'Valid hash found!' : 'NOT a valid hash!')

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda