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

162
Vistas
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 Respuestas
Responde la pregunta

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