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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay