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

88
Vistas
How to split numbers in an array into single digits

In my code, I receive an array with numbers. Some numbers are double digits or even tree digits. So it looks like this:

 [48, 48, 48, 48, 99, 52, 50, 100, 97, 101, 102, 51, 98, 100, 49, 100, 51, 100, 52, 53, 54, 57, 99, 49, 53, 52, 55, 51, 55, 52, 100, 57, 99, 56, 52, 49, 99, 99, 102, 52, 56, 50, 51, 55, 53, 49, 56, 97, 53, 101, 99, 53, 55, 54, 99, 57, 50, 97, 99, 56, 97, 50, 53, 53, 49, 54, 52, 55, 50, 54, 56, 57, 56, 50, 54, 54, 57, 50, 53, 55, 48]

And this is the code how I've achieved this:

function hashData(s) {
let hashArray = []; 

for(let i = 0; i < s.length; i++){
    let code = s.charCodeAt(i);
    hashArray.push(code);

}
hashArray.toString().split("")
console.log(hashArray)
return hashArray;

}

What I want to achieve is this:

[4, 8, 4, 8, 4, 8, 4, 8, 9, 9, 5, 2] //and so on.

As you can see I have tried the toString() method, but that doesn't seem to do anything.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You could join and get a new array.

const
    values = [1, 23, 456, 7890],
    result = Array.from(values.join(''), Number);

console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Just .join the input numbers into one long string, then turn it back into an array (of individual characters) and map to number.

const hashData = s => [...s.join('')].map(Number);

console.log(hashData([48, 48, 48, 48, 99, 52, 50, 100, 97, 101, 102, 51, 98, 100, 49, 100, 51, 100, 52, 53, 54, 57, 99, 49, 53, 52, 55, 51, 55, 52, 100, 57, 99, 56, 52, 49, 99, 99, 102, 52, 56, 50, 51, 55, 53, 49, 56, 97, 53, 101, 99, 53, 55, 54, 99, 57, 50, 97, 99, 56, 97, 50, 53, 53, 49, 54, 52, 55, 50, 54, 56, 57, 56, 50, 54, 54, 57, 50, 53, 55, 48]))

about 4 years ago · Juan Pablo Isaza 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