0

Reduce Higher Order Functions

 2 years ago
source link: https://dev.to/pushanverma/reduce-higher-order-functions-l13
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK