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

195
Views
¿Cómo puedo hacer una nueva matriz a partir de un emisor de eventos (da una matriz de bytes), donde el primer elemento de las nuevas matrices será '10' y el último '13'?

Tengo bytes entrantes de matrices una vez por vez. Se parece a esto

[10,12,34,58,62]

[83,33,23,44,13]

[10,12,34,58,62]

[34, 77,54,23,87]

[83,33,23,44,13]

[10,12,34,58,62]

[83,33,23,44,66]

[13] …continúa.

Entonces, representa cada matriz cada vez. Necesitaba que se renderizaran como

[10,12,34,58,62,83,33,23,44,13]

[10,12,34,58,62,34,77,54,23,87,83,33,23,44,13]

[10,12,34,58,62,83,33,23,44,66,13].

El primer elemento sera 10 y el ultimo 13. Alguien me puede ayudar con el codigo? Gracias por adelantado.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Si sus bytes entrantes son una matriz 2d, intente esto.

 let arr = [ [10, 12, 34, 58, 62], [83, 33, 23, 44, 13], [10, 12, 34, 58, 62], [34, 77, 54, 23, 87], [83, 33, 23, 44, 13], [10, 12, 34, 58, 62], [83, 33, 23, 44, 66], [13] ] let openedArr = [] for (let value of arr) { openedArr = [...openedArr, ...value] } let resultArr = [] let child = [] for (let value of openedArr) { child.push(value) if (value == 13) { resultArr.push(child) child = [] } } console.log(resultArr)

Explicación

  1. Cree una nueva matriz extendiendo toda la matriz entrante.
  2. Cree dos matrices resultArr y Child Array
  3. Empuje todos los elementos de la matriz a la matriz secundaria
  4. Si hay 13, entonces empuje la matriz secundaria a resultArr y vacíe la matriz secundaria.
about 4 years ago · Juan Pablo Isaza Report

0

// @param {accumulator} is array of array of numbers // @param {chunk} is the array of numbers // @return {accumulator} const process_bytes = (accumulator, chunk) => { if (accumulator && accumulator.length) { if (chunk && chunk.length) { if (chunk[0] === 10) { return [...accumulator, chunk]; } else { return [...accumulator.slice(0, accumulator.length - 1), [...accumulator[accumulator.length - 1], ...chunk]]; } } } return chunk && chunk.length && [chunk] || []; };

Suposición

El siguiente código sigue los datos de entrada proporcionados y la salida esperada en el OP


EJECUTAR EL CÓDIGO

 const process_bytes = (accumulator, chunk) => { if (accumulator && accumulator.length) { if (chunk && chunk.length) { if (chunk[0] === 10) { return [...accumulator, chunk]; } else { return [...accumulator.slice(0, accumulator.length - 1), [...accumulator[accumulator.length - 1], ...chunk]]; } } } return chunk && chunk.length && [chunk] || []; }; const testData = [ [10, 12, 34, 58, 62], [83, 33, 23, 44, 13], [10, 12, 34, 58, 62], [34, 77, 54, 23, 87], [83, 33, 23, 44, 13], [10, 12, 34, 58, 62], [83, 33, 23, 44, 66] ]; let processed_bytes = []; testData.forEach(x => { processed_bytes = process_bytes(processed_bytes, x); }); console.log(processed_bytes);



WYSIWYG => WHAT YOU SHOW IS WHAT YOU GET

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