// .reduce() = reduce the elements of an array // to a single value // ----------- EXAMPLE 1 ----------- const prices = [5, 30, 10, 25, 15, 20]; const total = prices.reduce(sum); console.log(`$${total.toFixed(2)}`); function sum(accumulator, element){ return accumulator + element; } // ----------- EXAMPLE 2 ----------- const scores = [75, 50, 90, 80, 65, 95]; const maximum = scores.reduce(getMax); const minimum = scores.reduce(getMin); console.log(maximum); console.log(minimum); function getMax(accumulator, element){ return Math.max(accumulator, element); } function getMin(accumulator, element){ return Math.min(accumulator, element); }
@Blitz61wasd Жыл бұрын
Django course please
@Praeda1910 ай бұрын
Dude, thank you SO much, the way you've explained how the three data transformation array methods work, as well as the how the forEach loop works, is incredibly easy to understand. I've finally got my head around how the forEach loop works, and now JS is (ifnally) starting to click with me. Again, thank you, and all the best!!
@javohir17048 ай бұрын
just restart
@RayhanAsif229 ай бұрын
Dude I've learned a lot from your videos !!
@Mochinori997 ай бұрын
This video is absolutely brilliant and so so clear. I love your videos. Thank you.
@pokerchannel69913 ай бұрын
.I have been trying to do everything with Array.from for example, I use it for summing let sum = 0.0 Array.from ( iter, (element, _) sum += element); see? no reduce. Reason? I don't know how to use reduce, yet. lol
@t.antonyjaneaustus31844 ай бұрын
Very good explaination dude..its more help full to me
@piotrmazgaj5 ай бұрын
This is my seal. I have watched the entire video, understood it, and I can explain it in my own words, thus I have gained knowledge. This is my seal.
@AdamGassouma7 ай бұрын
I did this : let username = ["Mr","Adam","Gassouma"]; let full = username.reduce(fullname); console.log(full); function fullname(previous,next){ return previous+" " + next; }
@zrotrasukha873311 ай бұрын
Thank you brother, you helped me a lot, May god bless you !!
@JayFullSnackDev3 ай бұрын
Thank you for explaining it very well!
@MikeCode-iy9sb6 ай бұрын
very good explaination. thanksSoMuch~
@devl0ver6668 ай бұрын
now i know why your channel name is bro code ................. :)
@vakyz53335 ай бұрын
I rarely comment. You're awesome!
@pexhay4690 Жыл бұрын
is there any difference between defining the callback that way and using arrow notation inside reduce like prices.reduce((accum, el) =>{...})
@ianfrye8988 Жыл бұрын
For the most part no, just depends on if you’re going to reuse that function… when you get into the “this” keyword it does depending on the context
@pexhay4690 Жыл бұрын
@@ianfrye8988 thank you
@pokerchannel69913 ай бұрын
I have been trying to do everything with Array.from for example, I use it for summing let sum = 0.0 Array.from ( iter, (element, _) sum += element); see? no reduce. Reason? I don't know how to use reduce, yet. lol
@cyberblitz9 ай бұрын
shame you didn't include the initial value parameter too. Otherwise, very educational.
@xxxharuxiao5 ай бұрын
oh my god you saved my life thank you!!!!!
@constdev_6 ай бұрын
//Using Arrow Function: //Arrow Function is awesome :D const grades = [70, 65, 75, 89, 94]; const maximum = grades.reduce((previous, next) => Math.min(previous, next)); console.log(maximum);
@nomanbangtan4120 Жыл бұрын
Bro you should do a project video.
@muhammetguloglu62686 ай бұрын
GOD BLESS YOU BRO!
@greengraphics5060 Жыл бұрын
Do a node js video
@pini507611 ай бұрын
thank you so much!
@IfyOkoro-k3r4 ай бұрын
Thanks bro 🙏🏼
@islamabdelhakiim72588 ай бұрын
thank you so much
@javohir17048 ай бұрын
would be a way better if you added a initialValue parameter but thank you though
@neko628013 ай бұрын
What would i do without you my bro
@youthpost_344 ай бұрын
Thanks Brooo👊
@allhailalona7 ай бұрын
good video, but what about objects? u forgot those.
@magomihaly1741 Жыл бұрын
You re the man thx bro
@TheRaviKumar44Ай бұрын
❤❤
@mahbubulislamridoy4493 ай бұрын
thanks sir
@kathikr936011 ай бұрын
thank you dude
@manitamao656410 ай бұрын
Thank u bro
@Blitz61wasd Жыл бұрын
django course please
@rukecodes Жыл бұрын
Thanks bro!!!!!!
@satyanarayanparida53167 күн бұрын
let myArry = [1,2,3,4,5,6,7]; const sum = myArry.reduce((accumulator, currentvalue) => accumulator + currentvalue ); console.log(sum);
@sangi297116 күн бұрын
.forEach () method , .map() method, .filter() method & . reduce () method = we are same bro ....😂
@yuvrajsingh-fz7hd3 ай бұрын
best
@kathikr93609 ай бұрын
thanks again
@samridhshubham81094 ай бұрын
GOAT
@ianfrye8988 Жыл бұрын
Also all other JavaScript higher order array methods can be created with reduce