Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
¿Cómo filtrar una matriz de números y tomar ciertos intervalos?

Tengo este tipo de matriz.

 [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]

Los requisitos para filtrar la matriz son

  1. Omitir cada 4 elementos
  2. Tome los siguientes 4 elementos

Y continúa hasta el final de la matriz.

Al final Debería volver [5,6,7,8,13,14,15,16,21,22,23,24]

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

 const values = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]; newValues = values.filter((v, i) => i % 8 > 3) console.log(newValues)

about 4 years ago · Santiago Trujillo Denunciar

0

Puede dividir los fragmentos y agregarlos a la matriz de resultados.

 const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], result = []; let i = 0; while (i < data.length) result.push(...data.slice(i += 4, i += 4)); console.log(...result);

about 4 years ago · Santiago Trujillo Denunciar

0

Puede crear una función de partición para lograr su resultado.

 const arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]; /** * Pertition the array and create a new array. * * @param {array} arr The array to pertition. * @param {number} skip The number of elements to skip * @param {number} take Take the number of elements need to take after skipping. * * @return {array} The resulting array after pertition. */ const arrayAfterPertition = (arr, skip, take) => { const length = arr.length; let ans = []; /** If there are not enough elements to skip then returns empty array */ if (length <= skip) return []; let takeIndex = skip; while (takeIndex < length) { ans = [...ans, ...arr.slice(takeIndex, takeIndex + take)]; takeIndex = takeIndex + take + skip; } return ans; } console.log(JSON.stringify(arrayAfterPertition(arr, 4, 4)));
 .as-console-wrapper {min-height: 100%!important; top: 0}

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda