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

197
Vistas
fill elements of an array on another array with respecting the size

How do I fill elements of an array on another array with respecting the size Example

Arra1 = ["1","2","3","4","5"]
Arra2 = ["R","B"]
result = ["R","B","R","B","R"]

How can I achieve that

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

0

You can write this :

r = []
let j = 0
for (let i=0; i<Arra1.length; i++)
{
    if (j>= Arra2.length)
        j = 0
    r.push(Arra2[j])
    j++
}

Hope it helps.

about 4 years ago · Santiago Trujillo Denunciar

0

You could do Array.map() with modulo %:

let Arra1 = ["1","2","3","4","5"]
let Arra2 = ["R","B"]
console.log(Arra1.map((num, ind)=>Arra2[ind%Arra2.length]))
//["R","B","R","B","R"]
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