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

183
Visualizações
Confusing on Reduce and Arrow function

I am now looking at the following post Javascript Algorithm Attempting to Implement Call Back Function. I can understand the other parts but particularly confuse at the following code. const sum = integerSet.reduce((total, item) => total + Math.pow(item, pow), 0);.
So, what is the purpose of adding 0 at the end and if we change from arrow function to normal function would it be change to this?
sum = integerSet.reduce(function(total, item) { return total + Math.pow(item,power),0; })
I have searched up the several reduce methods usage but still can't get the clear figure of how he use there so I decided to ask it here.

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

0

The 0 gives you the starting point. From there everything will be calculated "on top" of this accumulator. So in your example the 0 would be the item to start with.

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