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

159
Visualizações
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 à 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