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

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

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 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!