GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing es.javascript.info — Concatenar arrays tipados

  • Tutorial
  • Datos binarios y archivos
  • ArrayBuffer, arrays binarios
regresar a la lección

Concatenar arrays tipados

Dado un array de Uint8Array, escribir una función concat(arrays) que devuelva la concatenación de ellos en un único array.

Abrir en entorno controlado con pruebas.

function concat(arrays) {
  // suma de las longitudes de array individuales
  let totalLength = arrays.reduce((acc, value) => acc + value.length, 0);

  let result = new Uint8Array(totalLength);

  if (!arrays.length) return result;

  // para cada array: copiarlo sobre "result"
  // el siguiente array es copiado inmediatamente después del anterior
  let length = 0;
  for(let array of arrays) {
    result.set(array, length);
    length += array.length;
  }

  return result;
}

Abrir la solución con pruebas en un entorno controlado.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.