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

161
Views
Can anyone help me with my JavaScript code?

Question:

Create a method stupidHash, which takes a string and returns an int. It should sum of the squares of each character's value (obtained using charCodeAt and then subtracting 1), and return the division remainder of the sum when divided by 10.

These were the test examples given:

  1. console.log(stupidHash("")); results 0
  2. console.log(stupidHash("abc")); results 5
  3. console.log(stupidHash("1")); results 0

I'm a beginner with little knowledge in JavaScript. I tried my best but couldn't get the result.

My code:

function stupidHash(x){
    let sum=0;

    for(let i=0; i<x.length; i++){
        sum = sum + Math.pow(x.charCodeAt(i) , 2) -1;
    }
    return sum%10;
}

console.log(stupidHash("abc"));
about 4 years ago ยท Santiago Gelvez
1 answers
Answer question

0

It seems you just forget the ++ after the last i in the for.

for(let i=0; i<x.length; i++)

I don't have verified the math, but it console log some numbers ๐Ÿ˜

about 4 years ago ยท Santiago Gelvez 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!