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

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

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