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

157
Vistas
Codewars 6kyu - Data Reverse

There's a task. A stream of data is received and needs to be reversed. Each segment is 8 bits long, meaning the order of these segments needs to be reversed, for example:

11111111 00000000 00001111 10101010

should become:

10101010 00001111 00000000 11111111

I didn't understand the task and to solve the problem, I decide to make an object. Then make an array and transform input. Then sort y and get the result (In my head, it should work so, but...). But sometimes I get it, and sometimes forEach return undefined, and I don't know why? Where am I wrong? And why? I understand that this is not good way for solving problem. I find another way, but I want to know why sometimes do I get undefined?

function dataReverse(data) {
  let x = { '11111111': 1, '00000000':2, '00001111':3, '10101010':4, '1': '11111111', '2': '00000000', '3': '00001111', '4': '10101010', }
  let y = [] 
  data = data.join('').match(/\d{8}/g) 
  data.forEach(a=> y.push(x[a]))
  y = y.sort((a,b)=> b - a) 
  return y.map(a=> x[a]).join('').split('').map(a=> Number(a))
}
about 4 years ago · Juan Pablo Isaza
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