Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!