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

89
Views
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 answers
Answer question

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 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!