JavaScript Array Reduce

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ม.ค. 2025

ความคิดเห็น • 373

  • @haroldcjennettiii
    @haroldcjennettiii 4 ปีที่แล้ว +95

    Once again Mosh shows why he's one of the best coding teachers. You make things very clear, because you explain what EVERYTHING is, in laymen's terms. A lot of coding teachers forget they're teaching beginners.

  • @albatros280
    @albatros280 6 ปีที่แล้ว +460

    Finally... Somebody who explains reduce well. MDN documentation didn't help me.

    • @ginnerzapata5909
      @ginnerzapata5909 5 ปีที่แล้ว +39

      Just came from MDN 'cause I didnt understant a sheep!

    • @monfernape
      @monfernape 5 ปีที่แล้ว +7

      Exactly.

    • @kelechukwutasie4030
      @kelechukwutasie4030 5 ปีที่แล้ว +8

      You are very right! MDN didnt help at all...

    • @frownless
      @frownless 5 ปีที่แล้ว +2

      Ikr he is awesome

    • @damascanalexandru4998
      @damascanalexandru4998 5 ปีที่แล้ว +5

      So much clarity in 7 minutes video !

  • @RetroRick1990
    @RetroRick1990 4 ปีที่แล้ว +8

    Awesome , just understand what is the role of the "Accumulator" and the "Current Value" makes everything very clear. Thank man!

  • @clarinetisfying
    @clarinetisfying 3 ปีที่แล้ว +4

    I love he teaches coding very clearly in a short amount of time. He's the best coding teacher.

    • @msh1830
      @msh1830 2 ปีที่แล้ว

      th-cam.com/video/a_Bfu1XWGmI/w-d-xo.html

  • @WanBarmawi
    @WanBarmawi 3 ปีที่แล้ว

    The English is just so perfect for a non-native speaker like me. The explanation is so easy to understand too. Thank you so much, you get my subscription!

  • @tung01vuongtri33
    @tung01vuongtri33 2 ปีที่แล้ว +1

    finally, I can totally understand the reduce method thanks to you, appreciate your channel

  • @zdargahi
    @zdargahi 6 ปีที่แล้ว +69

    It would be great if you explain how the accumulation can be an array or object, and how when instead of chaining map and filter we can use reduce. I guess it's in the complete course.

    • @liamwelsh5565
      @liamwelsh5565 2 ปีที่แล้ว +1

      If you were using an array, you could return an array in the reduce, and spread the accumulator. Then add any new value after. Example:
      nums = [1,2,3,4,5]
      const doubledNums = nums.reduce( (acc, num) => [...acc, num*2], [ ])
      console.log(doubledNums) // [2,4,6,8,10]
      Obviosuly a .map could do the same thing but there are more complex examples where it is useful.

    • @Xetron1978
      @Xetron1978 2 ปีที่แล้ว

      @@liamwelsh5565 Hi, I'm very new to coding, may I know why did you add the "..." before acc? I'm not really sure what it does here

    • @liamwelsh5565
      @liamwelsh5565 2 ปีที่แล้ว +4

      @@Xetron1978 … is the spread operator. If you have an array, let’s call x and want to make a new array, let’s call y, that has all the values of x, you can spread x into y.
      Example:
      Const x = [1,2,3]
      Const y = […x]
      Console.log(y)
      // [1,2,3]
      You can also spread objects into objects

  • @johnisutsa1641
    @johnisutsa1641 5 ปีที่แล้ว +2

    How am I only finding your tutorials now. You explain so well. I'm taking you with me for the rest of my Java script journey.

  • @harwinderthakur9708
    @harwinderthakur9708 5 ปีที่แล้ว +8

    I spent 20 minutes on mdn understanding all this. I got more confused there.Thanks man

  • @onyeukwuhycient438
    @onyeukwuhycient438 2 ปีที่แล้ว +1

    This is by far the clearest explanation I've seen on the reduce method so far.. Thanks a lot Mr Mosh..

  • @Nessquickable
    @Nessquickable 6 ปีที่แล้ว +2

    Hadn't got used to that reduce method and was struggling for a while, only took me a minute of your explanation to spark a lightbulb in my head and I felt relieved. Thank you.

    • @msh1830
      @msh1830 2 ปีที่แล้ว

      th-cam.com/video/a_Bfu1XWGmI/w-d-xo.html

  • @rajabmuhamedrajab5128
    @rajabmuhamedrajab5128 4 ปีที่แล้ว +1

    Finally ... some who explain reduce well .Thanks

  • @shayanfaghihi
    @shayanfaghihi 2 ปีที่แล้ว

    I've explored every single line of MDN reference, but I didn't learn as much I could get from you. Appreciate that mate

  • @opasceptre
    @opasceptre 4 ปีที่แล้ว +1

    Boss more blessing to you, love from Nigeria. You just explained all MDN couldn't in minutes

  • @nashpaints
    @nashpaints 4 ปีที่แล้ว

    Been looking high and low for a simple explanation of the reduce method, and only now I have found it. Thank you.

  • @vedatsozen
    @vedatsozen 2 ปีที่แล้ว

    Thank really. I was making a project. I am adding tips of bills as % to a calculation machine and i need to sum all tips and print. At the end i succeeded by looking to your tutorial. Thanks so much.

  • @aiknowledge-n2s
    @aiknowledge-n2s 2 ปีที่แล้ว

    The first tutorial that made me understand reduce method. Thanks.

  • @RedBricksTraffic
    @RedBricksTraffic 2 ปีที่แล้ว +1

    Having it explained in video form is so much easier for me than reading it. Thank you!

    • @msh1830
      @msh1830 2 ปีที่แล้ว

      th-cam.com/video/a_Bfu1XWGmI/w-d-xo.html

  • @muthukumar8009
    @muthukumar8009 5 ปีที่แล้ว +1

    great explanation Mosh..
    [...Array(1000)].reduce((acc, elem) => {
    return acc + 'Thanks Mosh ';
    }, ['Great Explanation ']);

  • @timilehinoni
    @timilehinoni 3 ปีที่แล้ว

    By far the best explanation of reduce I have gotten haven watch tones of videos and tutorials

  • @MatchesMaloneThe3rd
    @MatchesMaloneThe3rd 4 ปีที่แล้ว +1

    Cleanest explanation I've seen so far. You just earned yourself a sub.

  • @dioncadiz
    @dioncadiz 4 ปีที่แล้ว

    Best method of teaching reduce method from complicated to its simplest possible form all under 10mins. You are amazing good sir. Thank you

  • @alvarosena858
    @alvarosena858 3 ปีที่แล้ว

    This video is posted a long time ago, but for the first time i understand reduce. Thanks Mosh!

  • @furn2313
    @furn2313 3 ปีที่แล้ว

    Mosh is everything a newbie needs!!!

  • @diegodmitry
    @diegodmitry 4 ปีที่แล้ว

    I'm from Brazil, but you explained so well. Thanks a lot!

  • @sogggy
    @sogggy 5 ปีที่แล้ว

    i just bought a 100 algorithms course from udemy.com. I prefer the way you teach. You explain everything thoroughly, the course instructor seemed to rush through the videos.

  • @EnricMartin1987
    @EnricMartin1987 ปีที่แล้ว

    Thank you Mosh. This is one of the best explanations about how to use reduce, that I could find on TH-cam.

  • @bevedel
    @bevedel 3 ปีที่แล้ว

    After watching this higher education, I was finally able to deeply understand it. Thank you!

  • @glantzdesign6239
    @glantzdesign6239 6 ปีที่แล้ว +1

    Thank you Mosh. I wish everyone can explain things as clearly as you.

  • @j.k.ravshanovich
    @j.k.ravshanovich 4 ปีที่แล้ว

    Explained better than MDN. Good job!

  • @mavs4life248
    @mavs4life248 10 หลายเดือนก่อน

    Thank you for breaking this down in detail. Very easy to understand.

  • @jame_sta
    @jame_sta 6 ปีที่แล้ว +1

    You're the BEST Instructor I've ever come across +ProgrammingwithMosh
    *sheds a tear* LOL :D -- I can't wait for more JS videos!!!!!

  • @millertime6
    @millertime6 5 ปีที่แล้ว +1

    Took me a while to get reduce even after learning all the other iteration methods. Thank you!

  • @brain8893
    @brain8893 2 ปีที่แล้ว

    Wow this guy is simply the best and you cannot dispute that

  • @АннаАгабекян-ю8т
    @АннаАгабекян-ю8т 4 ปีที่แล้ว

    Hooray, finally someone explained normally .. thank you very much!

  • @katebekatuka3447
    @katebekatuka3447 4 ปีที่แล้ว

    This explanation is way better than the documentation.

  • @ayromo7
    @ayromo7 5 ปีที่แล้ว

    Excellent explanation. I was confused how it worked until I saw this. Keep doing what you're doing man!

  • @rpb4865
    @rpb4865 2 ปีที่แล้ว +16

    Can anyone explain why for loop or foreach is "old way" and reduce is more "elegant way"?
    I find the"old way" more readable than the "elegant way"

    • @hamdiboujarra
      @hamdiboujarra 2 ปีที่แล้ว

      understand the elegant way and use the readable way if you want, after some months you will like to use the elegant way

    • @mikaelhelin6348
      @mikaelhelin6348 2 ปีที่แล้ว +1

      I also think the "old way" is better. The "elegant way" is limited to iteration of type y_n = f(y_{n-1}, x_n) where f is the callback function. There is this new movement in programming where people think old fashion for-loops are ugly code.

  • @sdwhitesox8039
    @sdwhitesox8039 5 ปีที่แล้ว

    "Just check MDN" does not help. These videos are the only things out there that actually explain anything. Thanks Mosh.

  • @marygracegardner2843
    @marygracegardner2843 2 ปีที่แล้ว

    Thank you dude, this is incredible. I wasn't understanding this before watching your video, thank you.

  • @mariodmp
    @mariodmp 6 ปีที่แล้ว +2

    This is super detailed, yet simple to understand, just great!

  • @olumorsotnas
    @olumorsotnas 2 ปีที่แล้ว

    Best code videos I ever watched. Thank you brother!

  • @ycombinator765
    @ycombinator765 4 ปีที่แล้ว +2

    Amazingly clear!! Functional Programming is the best ❤️

    • @msh1830
      @msh1830 2 ปีที่แล้ว

      th-cam.com/video/a_Bfu1XWGmI/w-d-xo.html

  • @vikaskad5737
    @vikaskad5737 2 ปีที่แล้ว

    one of the best explaination I ever watched

  • @sinamohammadi970
    @sinamohammadi970 2 ปีที่แล้ว

    Lovely explaination and lovely Mosh.
    We Love You Mosh, From Iran.

  • @floridaman7
    @floridaman7 2 ปีที่แล้ว

    This is a better description than coding academy.

  • @OMARCODER-zz4si
    @OMARCODER-zz4si 4 ปีที่แล้ว +1

    as usual, you make coding easy ...your explanation is great

    • @msh1830
      @msh1830 2 ปีที่แล้ว

      th-cam.com/video/a_Bfu1XWGmI/w-d-xo.html

  • @martinlipinski1403
    @martinlipinski1403 2 ปีที่แล้ว

    You are a king in easy explaining

  • @andyarellano7474
    @andyarellano7474 3 ปีที่แล้ว

    The best teacher so far

  • @Phoenix24Leas
    @Phoenix24Leas 4 ปีที่แล้ว +6

    This is nice but it'd be great if there was something on how to use reduce when making new objects/arrays

  • @gilbertrosario8633
    @gilbertrosario8633 6 ปีที่แล้ว +1

    Great tutorial, very well explained and easy to follow, I can finally say I understand the reduce method. Thanks you! Hope to see more tutorials like this in the future, like this key word, classes, call, bind, apply, etc.

  • @CrydonPT
    @CrydonPT 3 ปีที่แล้ว

    Thank you for explaining this right! No one seems to explain the first callback value as the accumulator but yet as the previous value.

  • @ahnaafarafee
    @ahnaafarafee 4 ปีที่แล้ว

    I was totally in the dark with this Reduce thing...thanks for explaining🙏 great help 👏👏👏

  • @ryansatriayudha
    @ryansatriayudha ปีที่แล้ว

    This is very clear and simple explanation!! Thank you very much 😊

  • @Sanyat100
    @Sanyat100 4 ปีที่แล้ว

    He the best teacher on the internet

  • @muhammadsultanularafin8846
    @muhammadsultanularafin8846 4 ปีที่แล้ว +1

    Wow! Explained in a super easy way. Thank you.

  • @nadeerahashankuruppu5962
    @nadeerahashankuruppu5962 4 ปีที่แล้ว

    Thank u for the great explanation
    let num = numbers.reduce((a,c) => a+=c ,2)

  • @slickchick8292
    @slickchick8292 3 ปีที่แล้ว +1

    Mosh, thank you so much! You broke this down into a very easy to understand way.

  • @kudafoolhu
    @kudafoolhu 4 ปีที่แล้ว

    Thank you. Better than any video out there.

  • @journeysalgado2972
    @journeysalgado2972 2 ปีที่แล้ว

    This made my brain hurt a lot less than the lesson I was reading. Thank you!

  • @niwanthakaweragoda9480
    @niwanthakaweragoda9480 4 ปีที่แล้ว

    Man, amazing explanation! So much better than some of the videos and websites I have seen on this topic!

  • @Chief_Sir_E.C.O._Nwuju
    @Chief_Sir_E.C.O._Nwuju 2 ปีที่แล้ว +1

    Thank you so much brother,your explanation was very simple and clear

  • @hebahamdi3855
    @hebahamdi3855 5 ปีที่แล้ว +1

    Thank you for making js clear and simple to understand

  • @augustineonyekachiadmiora9015
    @augustineonyekachiadmiora9015 4 ปีที่แล้ว

    Finally!!! Well explained in details. You’re a good man

  • @legitMeastro
    @legitMeastro 3 ปีที่แล้ว

    You are the best instructor mosh

  • @EssensOrAccidens
    @EssensOrAccidens 5 ปีที่แล้ว +2

    Thank you, Mosh. I found this very helpful for grasping the concept of reduce().

  • @xomgitsjay
    @xomgitsjay 3 ปีที่แล้ว

    Wow, so I was trying to understand this by reading it on MDN and it was just not sinking in. This helped SO much! Thank you good sir.

  • @justinlangley1056
    @justinlangley1056 4 ปีที่แล้ว

    Literally just spent an hour trying to figure this out from reading on MDN. I understood beforehand how reducing works. I'm familiar with the concept from a few other languages, which implement it more elegantly through lambda expressions. Javascript syntax can be odd at first, and it all came down to simple syntax errors I was making.

  • @md.bulbulislam2326
    @md.bulbulislam2326 3 ปีที่แล้ว

    Thank you so much for the beautiful explanation of reduce the method.

  • @moinkhan-xd6pe
    @moinkhan-xd6pe ปีที่แล้ว

    best coding teacher :)

  • @shehryar11yaqoob35
    @shehryar11yaqoob35 3 ปีที่แล้ว

    Such A smooth Explainer

  • @bobthehuntsman1548
    @bobthehuntsman1548 4 ปีที่แล้ว

    Thank you so much for this tutorial! Love the no-nonsense approach that any layman can pick up on :)

  • @bullz3718
    @bullz3718 3 ปีที่แล้ว

    MDN should hire you to do their video explanations. This was great!

  • @alejandrocuevas8999
    @alejandrocuevas8999 4 ปีที่แล้ว

    You’re the big boss. 😎😎😎 I went through other websites and videos but your explanation was the best.
    Thank you very much! I had the answer all time at home, since I was subscribed to your channel before. 🤩🤩🤩

  • @Pareshbpatel
    @Pareshbpatel 3 ปีที่แล้ว

    Nice explanation of the Reduce Method of arrays. Thanks, Mosh
    {2021-08-14}

  • @ernestj8000
    @ernestj8000 3 ปีที่แล้ว

    Excellent explanation of reduce function.

  • @benza435
    @benza435 3 ปีที่แล้ว +1

    1:11 prepare your sunglasses

  • @khaledMohamed-tp4wx
    @khaledMohamed-tp4wx 2 หลายเดือนก่อน

    Your way of explaining is nice

  • @ibrahimkedir5713
    @ibrahimkedir5713 4 ปีที่แล้ว

    Cheers, nice way of explaining things, I always pass ur videos when it pop ups now I watch and it's wonderful.

  • @Thoonjo
    @Thoonjo 3 ปีที่แล้ว

    you have made it simple man ! kudos

  • @nidhikumari4983
    @nidhikumari4983 3 ปีที่แล้ว

    thank you for explaning the basic concepts very clear...best explanation

  • @NITESHSINGHNRS
    @NITESHSINGHNRS 5 ปีที่แล้ว +1

    Best... Thank you sir...love from india.♥️

  • @spark8265
    @spark8265 3 ปีที่แล้ว

    My favourite teacher

  • @danbrown4781
    @danbrown4781 4 ปีที่แล้ว

    Great vid , helped me to finally jump that mental hurdle.

  • @code_fu552
    @code_fu552 5 ปีที่แล้ว +1

    Amazing!!! Thank u for breaking it down and explaining the components . Very helpful.

    • @msh1830
      @msh1830 2 ปีที่แล้ว

      th-cam.com/video/a_Bfu1XWGmI/w-d-xo.html

  • @norosoros891
    @norosoros891 หลายเดือนก่อน

    Nice and simple. Very well explained

  • @perfectionchizuruoke6207
    @perfectionchizuruoke6207 2 ปีที่แล้ว

    Thank you mosh you explained it perfectly

  • @cbehen
    @cbehen 2 ปีที่แล้ว +1

    actually, it must be accumulator += currentValue but just + works here maybe because of reduce method is holding the current value in memory for every iteration.

  • @angelsebastianbellomateo6954
    @angelsebastianbellomateo6954 4 ปีที่แล้ว

    I don’t even speak English that well and undestood everything! Thanks

  • @sandoxs
    @sandoxs 5 ปีที่แล้ว

    wonderful explanation!!! tnx for been there Mosh!!!

  • @bhavanachavan164
    @bhavanachavan164 4 ปีที่แล้ว

    interesting ... i like the way u teaching explaining...thank u so much....and keep it up....

  • @redone2728
    @redone2728 3 ปีที่แล้ว

    Simplicity is always key!

  • @sanyogyadav3913
    @sanyogyadav3913 2 ปีที่แล้ว

    thanks buddy for making concept clear

  • @milec7092
    @milec7092 3 ปีที่แล้ว

    Wow, so clear. Thanks, Mosh!!

  • @sauloferreiradossantos8158
    @sauloferreiradossantos8158 5 ปีที่แล้ว +1

    I have tried to do in the old fashion way using for(let i = 0;i

  • @drunkbutsober18
    @drunkbutsober18 2 ปีที่แล้ว

    Awesome explanation! Thank you for this!

  • @saleema6308
    @saleema6308 3 ปีที่แล้ว

    Brilliantly explained.

  • @encapsule2220
    @encapsule2220 2 ปีที่แล้ว

    this thing was making me pull my hair out, thanks mosh

  • @ritsk4338
    @ritsk4338 5 ปีที่แล้ว

    Great video on reduce(). Thankyou you have clear all my queries and doubts

  • @marcinkalmar9964
    @marcinkalmar9964 2 ปีที่แล้ว

    very easy to understand by good explanation