Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

90
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda