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

131
Visualizações
reverseArray() codeademy using unshift()
// Using the .unshift() method
const reverseArray = arr => {
    let reversed = [];
    for (let i = 0; i < arr.length; i++) {
        reversed.unshift(arr[i]);
    }
    return reversed
}

if we want to reverse order the last element will become the first.How can this method reverse the order when it starts at first index?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Based on this:

The unshift() method adds new items to the beginning of an array, and returns the new length

So in each iteration you are adding item to the beginning of an array and when iteration is done you have reversed array.

about 4 years ago · Juan Pablo Isaza Relatório

0

"array.unshift()" is use to push items into array, you need to use "array.reverse()" to reverse the array.

const arr = [1, 2, 3];
arr.unshift(4, 5);
console.log(arr);
// reverse
arr.reverse(arr, "this is unshift");
console.log(arr, "this is reverse");

// output: arr [4, 5, 1, 2, 3]

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