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

255
Vistas
¿Cómo crear una matriz a partir de valores semilla que llene la matriz con un límite máximo dado?

Necesito una función para crear una matriz usando 2 valores tales que:

  • length : se utiliza para determinar la nueva longitud de la matriz
  • maxIndexValue : se utiliza para determinar el valor máximo en un índice de matriz determinado antes de volver a empezar en 0.

ejemplo:

 // length and maxIndexValue are integer values. function buildArray(length, maxIndexValue){ // TODO: Implementation return array; } let newArray = buildArray(16, 3) // newArray should be [0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3] console.log(newArray);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Esto se puede lograr utilizando el operador mod % .

 function buildArray(length, maxIndexValue) { const arr = new Array(length); for (let a = 0; a < length; a++) { // Using the mod % operator // 0 % 4 = 0 // 1 % 4 = 1 // 2 % 4 = 2 // 3 % 4 = 4 // 4 % 4 = 0 // 5 % 4 = 1 // .. so on arr[a] = a % (maxIndexValue + 1); } return arr; } let newArray = buildArray(16, 3); console.log(newArray);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Puede lograr fácilmente el resultado usando el operador % como

 Array(length) .fill(0) .map((_, i) => i % (maxIndexValue + 1));

o

 new Array(length).fill(0).map((_, i) => i % (maxIndexValue + 1)); 

 function buildArray(length, maxIndexValue) { return Array(length) .fill(0) .map((_, i) => i % (maxIndexValue + 1)); } const length = 16, maxIndexValue = 3; let newArray = buildArray(length, maxIndexValue); console.log(newArray);

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