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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.