DEV Community

PUSHAN VERMA
PUSHAN VERMA

Posted on

2

Reduce Higher Order Functions

*Reduce Higher Order Functions *

Learning with the help of exapmle :-

const arr =[2,3,4,5,6];

// c is a procedural language
// c++ and java is a object oriented language
// javascript is a functional programming language

//reduce returns only single time after executing the whole program

let addition =arr.reduce(function(sum,value){
let updatedsum =sum+value;
return updatedsum
},0)

console.log(addition);

// ๐Ÿ‘‰ans ->20

let multiplication =arr.reduce(function(product,value){
let updatedproduct =product*value;
return updatedproduct
},1)

console.log(multiplication);

// ๐Ÿ‘‰ans->720

//๐Ÿ“Œ๐Ÿ“ŒReduceRight
// (It is same as reduce , only diffrence is that it runs from right)
let addition1=arr.reduceRight(function(sum,value){
let updatedsum1=sum+value;
return updatedsum1
},0)

console.log(addition1);

// ans->20

For hand written notes :
https://github.com/pushanverma/notes/blob/main/webd/Reduce%20.pdf

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series ๐Ÿ“บ

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series ๐Ÿ‘€

Watch the Youtube series