Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!