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

192
Views
Reimplement/Recreate the .concat method without using any built-in array methods

I am currently doing a challenge where we have to reimplement various array methods without using the built in array methods. I've done almost all of them except the concat. With the concat, we have to make sure that it returns a single array with every element from the inputs regarding the parameters.

function newConcat(...item) {
  let newArray = [...item];
  return newArray;
}

This works for the most part but when it takes in arrays, it keeps them separate so it ends up being an array of arrays instead of just one large array that has been concatenated .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I did it using spread operator, respecting your function parameters definition:

function newConcat(...arrays) {
    let result = [];
    for(let x = 0; x < arrays.length; x++) {
        result = [...result, ...arrays[x]]; // using spread
    }
    return result;
}

console.log(newConcat([1, 2, 3], [4, 5, 6]));

Not sure if your challenge will accept the spread operator, so there is a more simple code version:

function newConcat(...arrays) {
    let result = [];
    for(let x = 0; x < arrays.length; x++) {
        const item = arrays[x];
        for(let y = 0; y < item.length; y++) {
            result.push(item[y]);
        }
    }
    return result;
}

console.log(newConcat([1, 2, 3], [4, 5, 6]));

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