typestar

Partir un arreglo en JavaScript

Parte un arreglo en piezas de tamaño fijo, para agrupar peticiones o armar una cuadrícula.

function chunk(items, size) {
  if (size < 1) throw new Error("size must be positive");
  const out = [];
  for (let i = 0; i < items.length; i += size) {
    out.push(items.slice(i, i + size));
  }
  return out;
}

Palabras clave y builtins usados aquí

El intento, en números

Líneas
8
Caracteres a escribir
200
Tokens
66
Ritmo de tres estrellas
90 tpm

Al ritmo de tres estrellas de 90 tokens por minuto, este intento toma unos 44 segundos.

Escribe este fragmento

Paso 4 de 10 en Arreglos; paso 20 de 43 en Fundamentos del lenguaje.

← Anterior Siguiente →