Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda