For anyone learning JavaScript I find this absolutely imperative. Amazing video!
@leighhalliday4 жыл бұрын
Thank you very much, Eric! Glad you enjoyed it :)
@prinzadamz Жыл бұрын
True ✌
@metasavagex4 жыл бұрын
This is why you're awesome, definitely showing the power of reduce, other tutorials just play around with it with adding values. Thank you for this 🔥 content!
@leighhalliday4 жыл бұрын
Thanks James! Glad you found it useful!
@piyushaggarwal52072 жыл бұрын
Reduce is really cool man. Fun fun function guy told us that reduce can do map, filter and everything but didn't tell how. Saving your video for watching in detail later.
@alasdair71962 жыл бұрын
BROOOOOO!! I have never understood how to use reduce, like at all...I do now. Thank you so much. Liked, saved and subscribed!
@adibirta3 жыл бұрын
20:23 These kind of moments are priceless :)) Great video! Thanks!
@leighhalliday3 жыл бұрын
:D Thanks!!
@newmagicfilms3 жыл бұрын
Finally.... after all these years as a developer, I clearly understand it! Thank you!
@0xmarrakesh2882 жыл бұрын
Thank you a lot, friend! It was getting hard to wrap my head around the concenpt but now I finally get it! :)
@danielluna76483 жыл бұрын
This could be the single most helpful video I've seen all year. I had no idea how powerful reduce was. Get the concept of the accumulator down and it makes so many difficult tasks much easier. Great video. I would love to see more of these on other object and array functions. This was 🔥🔥🔥🔥🔥🔥
@PavanSibal Жыл бұрын
The best reduce tutorial. Thank you.
@MicheleBloodphd2 жыл бұрын
If you are struggling to wrap your head around JavaScript's REDUCE method, this is the video you want to watch. No need to look any farther. THIS IS THE ONE!
@MakdoKro3 жыл бұрын
Big ty !!! thats the 1st video about reduce() which gives a good full explanation !
@mrkhoros4 жыл бұрын
Your dominance over arrays and objects is incredible. Please put more videos about these simple methods with these types of usages. Thanks.
@leighhalliday4 жыл бұрын
Haha... thanks :D But there's no need for anything else, only reduce!! Haha. Stay tuned for more vids in the future ;)
@lucasae41402 жыл бұрын
This is the first reduce tutorial I found that actually shows the value and versatility of reduce. hats off to you. I've been studying the methods shown in this video and I think my brain has bled at least a full gallon. this is such good and difficult study material. Thank you!
@ianfinley30122 жыл бұрын
Best description I have seen opening this up. Worlds ahead of anything else out there. Thank you!
@FromTheHeart-7774 жыл бұрын
Omgggg ty. Everyone else's tutorials just have a set of numbers in their example. Your tutorial is more realistic on what is common. Thanks so much for having the intuition to have this tutorial. Subscribed!!
@leighhalliday4 жыл бұрын
Haha... thanks :) Glad you enjoyed it! I try to use realistic examples whenever possible.
@Rob345703 жыл бұрын
Me too, instant sub! Thanks for the realistic examples, exactly what I was looking for
@21agdmnm2 жыл бұрын
every freaking reduce video on youtube use the same example.. sum of some numbers.. FINALLY .reduce explained well!
@mrWorldwideJuan2 жыл бұрын
For anyone learning JS right now, this is a must-watch. Thanks for sharing it!
@leighhalliday2 жыл бұрын
Thanks Juan! Glad it helped :)
@araazizi79083 жыл бұрын
This video single handedly taught me A LOT of stuff that used to make JS look like a big question mark in my head lol kudos
@eraldoabedini46422 жыл бұрын
One of the best videos so far
@thydevdom3 жыл бұрын
THANK YOU THANK YOU THANK YOU! My instructor kept telling me that my code was fine but needed to implement reduce and shorten my code. You are a life saver. No other video made sense.
@leighhalliday3 жыл бұрын
Reduce is like having super powers!
@cliffclof3 жыл бұрын
@21:14 i think this is what he meant by hand implement a reduce. Nice overview.
@jpetty55422 жыл бұрын
Great vid! Very good examples and explanations. By far this was the best video on reduce I found.... And I've watched a lot lmao. Thanks again
@viqtorione Жыл бұрын
Wonderful. Crystal clear. Thank you.
@dimimav44184 жыл бұрын
Hey Leigh thank you for the video. I was a little confused with the all and any over 18 implementations but i will watch again and try to wrap my head around!
@leighhalliday4 жыл бұрын
Thanks Jim! Maybe I just didn't explain it very well :D Play around with it on your own and try to come up with some examples.. that's how you'll get more comfortable with it!
@slickchick82923 жыл бұрын
I finally understand how to use reduce. I have been so scared of using it. Thank you for this video.
@leighhalliday3 жыл бұрын
Nice! Glad it helped :) Do not fear reduce!
@diogosoares13093 жыл бұрын
Loved the flatten one and the counting! Your simplicity explaining is superb, Leigh!
@leighhalliday3 жыл бұрын
Thank you so much Diogo! I love playing with data like this.
@kissromeorichard2 жыл бұрын
Thank you so much for the explanation and examples! Yep, you definitely made me like reduce and not hate it :D
@rezahosseini78514 жыл бұрын
I finally did it! I finally learned reduce!! Thank you!
@leighhalliday4 жыл бұрын
I'm proud of you Reza!! Thanks for your support :)
@Ahmed-cy4jp3 жыл бұрын
This is my very favorite tutorial. I finally learned how this awesome method works, and in fact I built my own version of reduce and it basically returned the exact same outputs that the built-in reduce method returns! Thank you so much
@leighhalliday3 жыл бұрын
Nice!! That’s awesome Ahmed! Glad it helped.
@Ahmed-cy4jp3 жыл бұрын
@@leighhalliday I used all the examples you shared on this video, to make sure it produces the same output, and it actually did :D
@victorlindh31292 жыл бұрын
Awesome examples! Thank you so much for this!
@soltiscd4 жыл бұрын
This is the way to learn and understand. Love all your content.
@leighhalliday4 жыл бұрын
Thank you very much, Salty!
@mehinhuseynova14263 жыл бұрын
Thank you. Explanation and examples are perfect.
@leighhalliday3 жыл бұрын
Thanks Mehin!
@rorycawley2 жыл бұрын
Great vid, thank you Leigh.
@x4r73 жыл бұрын
best reduce explanation
@marcellvieira37134 жыл бұрын
Spectacular! Greetings from Venezuela
@leighhalliday4 жыл бұрын
Thank you! Right back at you from Canada :)
@videostothepoint55053 жыл бұрын
Superb explanation. Thank you.
@omedjamal10563 жыл бұрын
Thanks for this great explanation.
@leighhalliday3 жыл бұрын
You're very welcome! Glad you enjoyed it Omed!
@Booboosik3 жыл бұрын
For "max age" @7:50 use Math.max with comparing to -Infinity (negative infinity), that will make any negative number larger than the initial comparison.
@leighhalliday3 жыл бұрын
Thanks!! Good trick! Or you can use the first value of the array
@ridl274 жыл бұрын
thank you. probably the only one array method that I always trying to avoid lol xD but now, hopefully, I will use it as much as I can! :D
@leighhalliday4 жыл бұрын
Embrace the reduce!!
@MariaMartinez-bz7zw2 жыл бұрын
Great video! Thank you so much!
@fernandoortiz18493 жыл бұрын
thank you for not using a freaking sum of nums example to explain reduce, thumbs up!
@abelmurua69803 жыл бұрын
Amazing video! Awesome examples. Im having issues with moderno js where you dont use else or curly braces, etc.. so I watse time on that. This helps.
@demarco69674 жыл бұрын
This is very helpfull. thanks so much leigh 🔥😄
@leighhalliday4 жыл бұрын
Thanks Primordial!! Glad you enjoyed it :)
@CoryTheSimmons4 жыл бұрын
>Reduce may be the most versatile function in JavaScript 1000% agree. Almost every other function can be replicated with reduce. I reach for this pattern almost anytime I need to cleanup an array of objects: ```js arrOfObjs.reduce((acc, curr) => { const freshObj = {} freshObj.someKey = curr.someVal acc.push(freshObj) return acc }, []) ```
@gidmanone4 жыл бұрын
couldn't you simply map?
@leighhalliday4 жыл бұрын
Thanks Cory! To gidmanone's point, yup I think you could use map for this if you are doing a 1 for 1 mapping of array elements to array elements.
@vaylx22533 жыл бұрын
Hey Leigh, I can't believe it took my so long to discover this channel! This video is an absolute blessing 💛 One question for you, in the "Convert to ID => Person Lookup (dict)" reduce function, you used the computed property name shorthand by writing: "[person.id] : person" to set the key to "person.id". Kindly, could you tell me how to achieve this without using the shorthand? Like how would you implement this manually? Many thanks!
@leighhalliday3 жыл бұрын
Hey Vayl! You can totally do it in multiple lines... something like this? acc[person.id] = person; return acc;
@emersonaraujo4064 жыл бұрын
Congratulations for always bringing us top content. Thanks for your work.
@leighhalliday4 жыл бұрын
Much appreciated!
@juhandvan4 жыл бұрын
thank bro, i really love this tutorial
@leighhalliday4 жыл бұрын
Thank you Juhand! Glad you enjoyed it!
@thetech36242 жыл бұрын
I had a question at 15:29, the count occurrences example. Is the accumulator always a number but returns what you want (in that case an object) at the end? Sort of like a double functioning tool? Also, what did you mean by '2 or 5' at 15:16? And overall, I'm not really sure how `acc[order.status]` returns a number. All help is appreciated, thank you.
@erikshumkov48483 жыл бұрын
Thanks for sharing, great examples! Now it's time to implement some of these.
@leighhalliday3 жыл бұрын
Oh yea! Reduce is so useful! I hardly ever use recursion, but I use reduce almost daily.
@adityadubey52043 жыл бұрын
Thankyou so much for this really needed this :)
@leighhalliday3 жыл бұрын
Glad it helped! :)
@joelexperienced2 жыл бұрын
hey man! thanks for the practice :)
@pegahfallah37703 жыл бұрын
this was a great video
@rajeshsahu30734 жыл бұрын
Well explained video..Your way of teaching is cool..Could you please make a video on how to implement multilevel (3 to 4 levels deep) menu in react?
@leighhalliday4 жыл бұрын
Hey Rajesh! I'll keep it in mind, but I tend to shy away from the purely UI frontend stuff because that isn't my strong area :D
@TheBayouCritter3 жыл бұрын
This is great, thanks so much. I don't quite get why we need a separate function on the flatten example, is reduce just not capable of calling itself?
@leighhalliday3 жыл бұрын
No, i don’t believe you can call yourself in a reduce… need a separate named function.
@coolworx Жыл бұрын
I love reduce... const activities = ['hiking', 'cycling', 'programming', 'photography', 'fishing', 'hunting', 'camping' ]; const list = activities.reduce((ul, activity) => { const li = document.createElement('LI'); li.innerText = activity; ul.appendChild(li); return ul; }, document.createElement('UL'));
@SLRModShop3 жыл бұрын
Brilliant video, everyone else is showing the bare minimum...
@danielluna76483 жыл бұрын
Question: for short circuiting the accumulator once you find what you're looking for, couldn't you still use reduce, but when you find what you're looking for, assign that value to accumulator, break, then return the accumulator with that new assigned value?
@misterl81293 жыл бұрын
no, reduce cannot be broken. Just classic for and foreach
@misterl81292 жыл бұрын
@@capslock3250 totally right i get the wrong names lol, thx
@OsamaQarem4 жыл бұрын
you explain so well!!
@leighhalliday4 жыл бұрын
Thank you Osama!
@elkhanhamet25614 жыл бұрын
thank you Leigh!!!
@leighhalliday4 жыл бұрын
You're very welcome :)
@gregfletcher23604 жыл бұрын
Hey Leigh! Great video, Here's my solution to the condition reducer. I would like to see a better method since I only just hacked it together in a minute. function conditionalReducer(array, cb, initial, condition) { let acc = initial; for (let i = 0; i < array.length; i += 1) { acc = cb(acc, array[i], i, array); if (condition === acc) return acc; } return acc; }
@leighhalliday4 жыл бұрын
Thanks Greg!! I added my condition to the repo I shared in the description :D no idea if it's a good one haha!
@gregfletcher23604 жыл бұрын
@@leighhalliday Sweet. I'll check it out! Thanks for the video again! I love the quality of the content!
@thanapolraktham22913 жыл бұрын
Thanks a lot!
@AndersonSilvaMMA4 жыл бұрын
Thanks for your video!
@leighhalliday4 жыл бұрын
You're welcome!! Didn't realize Anderson Silva was a JS developer! Love your fights! Obrigado!
@seenaranjith2 жыл бұрын
great videos. I have a question about result = people.reduce((acc, person) => { return { ...acc, [person.id]: person }; }, {});. If we are grouping names instead of id and have more than one same name, how can we rewrite this code?.
@finnbit11554 жыл бұрын
I just watched your mapbox video and I was wondering if you could have the website open so anyone can add markers and add to thoughs details?
@leighhalliday4 жыл бұрын
Hey Finn!! I think you'd want to: 1) Listen to click event on map... to get the coordinates. 2) Ask the user for the details they want to place in this marker. 3) Send this data to a backend to store it somewhere... otherwise it's lost 4) Add this marker to your array/state of markers so that when it re-renders it is shown on the map.
@akashnag38793 жыл бұрын
this is the answer to me reduce method quest. everyone just shows how to just add elements of an array.. that's it
@leighhalliday3 жыл бұрын
Haha... I tried to make it practical... reduce has so many uses!
@emrahburak86843 жыл бұрын
Wow. Thanks.
@leighhalliday3 жыл бұрын
You're very welcome Emrah!
@gradientO4 жыл бұрын
Can you do a video on some react ui components, like Material UI?
@leighhalliday4 жыл бұрын
Hey g g! Maybe at some point in the future... I'm 90% backend dev, so I prefer to stay away from the super visual stuff... it isn't where I feel confident.
@mouradaouinat87214 жыл бұрын
amazing video
@leighhalliday4 жыл бұрын
Thank you Mourad!
@CarlosSz4 жыл бұрын
Amazing video! Can you please make a video like this with filter? 👀
@leighhalliday4 жыл бұрын
To recreate filter using reduce, or just to cover filter in general? Here's a minimal reduce example: array.reduce((acc, element) => { if (true) return [...acc, element] return acc }, []);