JavaScript reduce() method in 5 minutes! ♻️

  Рет қаралды 34,016

Bro Code

Bro Code

Күн бұрын

// .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);
}

Пікірлер: 40
@BroCodez
@BroCodez 11 ай бұрын
// .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
@Blitz61wasd 11 ай бұрын
Django course please
@Praeda19
@Praeda19 6 ай бұрын
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!!
@javohir1704
@javohir1704 5 ай бұрын
just restart
@AdamGassouma
@AdamGassouma 3 ай бұрын
I did this : let username = ["Mr","Adam","Gassouma"]; let full = username.reduce(fullname); console.log(full); function fullname(previous,next){ return previous+" " + next; }
@Mochinori99
@Mochinori99 4 ай бұрын
This video is absolutely brilliant and so so clear. I love your videos. Thank you.
@devl0ver666
@devl0ver666 4 ай бұрын
now i know why your channel name is bro code ................. :)
@cyberblitz
@cyberblitz 5 ай бұрын
shame you didn't include the initial value parameter too. Otherwise, very educational.
@piotrmazgaj
@piotrmazgaj Ай бұрын
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.
@RayhanAsif22
@RayhanAsif22 6 ай бұрын
Dude I've learned a lot from your videos !!
@t.antonyjaneaustus3184
@t.antonyjaneaustus3184 Ай бұрын
Very good explaination dude..its more help full to me
@zrotrasukha8733
@zrotrasukha8733 8 ай бұрын
Thank you brother, you helped me a lot, May god bless you !!
@MikeCode-iy9sb
@MikeCode-iy9sb 3 ай бұрын
very good explaination. thanksSoMuch~
@javohir1704
@javohir1704 5 ай бұрын
would be a way better if you added a initialValue parameter but thank you though
@vakyz5333
@vakyz5333 2 ай бұрын
I rarely comment. You're awesome!
@nomanbangtan4120
@nomanbangtan4120 11 ай бұрын
Bro you should do a project video.
@greengraphics5060
@greengraphics5060 8 ай бұрын
Do a node js video
@pexhay4690
@pexhay4690 11 ай бұрын
is there any difference between defining the callback that way and using arrow notation inside reduce like prices.reduce((accum, el) =>{...})
@ianfrye8988
@ianfrye8988 11 ай бұрын
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
@pexhay4690 10 ай бұрын
@@ianfrye8988 thank you
@constdev_
@constdev_ 3 ай бұрын
//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);
@allhailalona
@allhailalona 4 ай бұрын
good video, but what about objects? u forgot those.
@muhammetguloglu6268
@muhammetguloglu6268 3 ай бұрын
GOD BLESS YOU BRO!
@xxxharuxiao
@xxxharuxiao Ай бұрын
oh my god you saved my life thank you!!!!!
@Blitz61wasd
@Blitz61wasd 11 ай бұрын
django course please
@pini5076
@pini5076 7 ай бұрын
thank you so much!
@samridhshubham8109
@samridhshubham8109 13 күн бұрын
GOAT
@islamabdelhakiim7258
@islamabdelhakiim7258 4 ай бұрын
thank you so much
@neko62801
@neko62801 9 күн бұрын
What would i do without you my bro
@IfyOkoro-k3r
@IfyOkoro-k3r 16 күн бұрын
Thanks bro 🙏🏼
@youthpost_34
@youthpost_34 Ай бұрын
Thanks Brooo👊
@magomihaly1741
@magomihaly1741 10 ай бұрын
You re the man thx bro
@mahbubulislamridoy449
@mahbubulislamridoy449 6 күн бұрын
thanks sir
@kathikr9360
@kathikr9360 7 ай бұрын
thank you dude
@rukecodes
@rukecodes 10 ай бұрын
Thanks bro!!!!!!
@manitamao6564
@manitamao6564 6 ай бұрын
Thank u bro
@kathikr9360
@kathikr9360 6 ай бұрын
thanks again
@ianfrye8988
@ianfrye8988 11 ай бұрын
Also all other JavaScript higher order array methods can be created with reduce
JavaScript FUNCTION EXPRESSIONS in 7 minutes! 🐣
7:32
Bro Code
Рет қаралды 18 М.
Learn JavaScript OBJECTS in 7 minutes! 🧍
7:01
Bro Code
Рет қаралды 61 М.
Which One Is The Best - From Small To Giant #katebrush #shorts
00:17
How to FETCH data from an API using JavaScript ↩️
14:17
Bro Code
Рет қаралды 135 М.
Array Methods in JavaScript | 17 Useful Methods
42:39
DoableDanny
Рет қаралды 57 М.
JavaScript map() method in 7 minutes! 🗺️
7:01
Bro Code
Рет қаралды 39 М.
JavaScript DESTRUCTURING in 8 minutes! 💥
8:41
Bro Code
Рет қаралды 21 М.
What are JavaScript PROMISES? 🤞
12:37
Bro Code
Рет қаралды 66 М.
JavaScript CONSTRUCTORS in 5 minutes! 🛠
5:32
Bro Code
Рет қаралды 33 М.
Learn JavaScript SORTING in 6 minutes! 🗃
6:42
Bro Code
Рет қаралды 25 М.
Build this JS calculator in 15 minutes! 🖩
15:20
Bro Code
Рет қаралды 586 М.
JavaScript ASYNC/AWAIT is easy! ⏳
4:39
Bro Code
Рет қаралды 84 М.
Which One Is The Best - From Small To Giant #katebrush #shorts
00:17