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 sing…


This content originally appeared on DEV Community and was authored by PUSHAN VERMA

*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


This content originally appeared on DEV Community and was authored by PUSHAN VERMA


Print Share Comment Cite Upload Translate Updates
APA

PUSHAN VERMA | Sciencx (2022-02-14T14:07:40+00:00) Reduce Higher Order Functions. Retrieved from https://www.scien.cx/2022/02/14/reduce-higher-order-functions/

MLA
" » Reduce Higher Order Functions." PUSHAN VERMA | Sciencx - Monday February 14, 2022, https://www.scien.cx/2022/02/14/reduce-higher-order-functions/
HARVARD
PUSHAN VERMA | Sciencx Monday February 14, 2022 » Reduce Higher Order Functions., viewed ,<https://www.scien.cx/2022/02/14/reduce-higher-order-functions/>
VANCOUVER
PUSHAN VERMA | Sciencx - » Reduce Higher Order Functions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/14/reduce-higher-order-functions/
CHICAGO
" » Reduce Higher Order Functions." PUSHAN VERMA | Sciencx - Accessed . https://www.scien.cx/2022/02/14/reduce-higher-order-functions/
IEEE
" » Reduce Higher Order Functions." PUSHAN VERMA | Sciencx [Online]. Available: https://www.scien.cx/2022/02/14/reduce-higher-order-functions/. [Accessed: ]
rf:citation
» Reduce Higher Order Functions | PUSHAN VERMA | Sciencx | https://www.scien.cx/2022/02/14/reduce-higher-order-functions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.