Reduce: Mother of all Javascript Array Methods? (Part 5)

  Рет қаралды 15,802

Jack Herrington

Jack Herrington

Күн бұрын

Reduce is considered the hardest of the Array functions, is it? Let's try demystifying this super powerful Array method and give you the power to create anything you want from an arry.
Quokka: quokkajs.com/
Code: github.com/jherr/arrays-made-...
👉 What's my theme? Night Wolf [black]
👉 What's that font? Operator Mono
👉 I'm a host on the React Round Up podcast: devchat.tv/podcasts/react-rou...
👉 Don't forget to subscribe to this channel for more updates: bit.ly/2E7drfJ
👉 Discord server signup: / discord
00:00 Introduction
00:35 Reducing to a single value
06:50 Reducing to an array
11:55 Reducing to an object
15:55 Reduce can make all the other array methods
18:40 Entries, keys and values
21:00 Reduce for sequential async
22:51 Review
23:25 Outroduction
Thank you for watching this video, click the "SUBSCRIBE" button to stay connected with this channel.
#javascript #arrays

Пікірлер: 63
@muhammadyousufhere
@muhammadyousufhere Жыл бұрын
Can't believe!! You literally have summed up almost everything Js in one video.
@dgcp354
@dgcp354 2 жыл бұрын
One of your typescript challenges where to do everything other methods do with reduce method, I was blown away when I learned it
@mikef.606
@mikef.606 Жыл бұрын
This is better than Netflix.
@lazarstanev866
@lazarstanev866 2 жыл бұрын
I have no doubt this is the most underestimated channel on KZbin. You are doing an amazing job and in every video I'm learning something new. Thank you very much!
@user-ze1zp9cp5u
@user-ze1zp9cp5u 2 жыл бұрын
Reduce is my favourite method for arrays. So powerful especially when initializing an object but at same time looping through the array. Love the series!
@AbdelhameedG
@AbdelhameedG 2 жыл бұрын
Amazing Jack, Keep it up you are definitely the leader of JS/TS/React/Frontend community.
@basharkhadra2929
@basharkhadra2929 2 жыл бұрын
100% coverage of reduce functionality. Thanks a lot 👍
@LuisFelipe-td8qk
@LuisFelipe-td8qk 2 жыл бұрын
Come on, Jack! You are a blessing for all programmers. Thank you so much, I think I'm about to finish all of your videos.
@user-gh6tc1bf9h
@user-gh6tc1bf9h 2 жыл бұрын
absolutely complete stuff !! keep going !
@johannsebastianbach3411
@johannsebastianbach3411 2 жыл бұрын
Wow that async reduce hack sure is smart!! Great video as always!!
@shinmessiah
@shinmessiah 2 жыл бұрын
Great content and explanation sir as per usual
@mdrahiem_dev
@mdrahiem_dev 2 жыл бұрын
I wasn't confident about reduce method till now.. thanks much for the video..
@designdeveloprepeat651
@designdeveloprepeat651 2 жыл бұрын
Great video as always!
@marcelsdev
@marcelsdev 2 жыл бұрын
Great comparison examples! "Mother" will be proud! :D
@theyreMineralsMarie
@theyreMineralsMarie 2 жыл бұрын
Reduce in JavaScript is actually really easy because the parameters arent typed. You can just throw anything in for the identity and then change it however you want on each iteration. I like using reduce to convert and array of objects to an object with specific keys.
@adamlerman4173
@adamlerman4173 2 жыл бұрын
Thank you for another awesome video!
@maltegb
@maltegb 2 жыл бұрын
Great Content, keep up!
@MrPlaiedes
@MrPlaiedes 2 жыл бұрын
Great video man!
@hooked-to-coding
@hooked-to-coding Жыл бұрын
As I understand it and experienced while coding, .reduce() starts at index 1 when you use it to create a single string from an array of strings. Checking if index > 0 at min 06:01 doesn't really change anything because there is index 0. You might as well left is that way: => str + ", " + name Correct me, if I got it wrong. But thank you nevertheless for all you free and valuable videos. You and Dave Gray are my top resources when it comes to Java Script or React and both of you deserve so much more likes and followers!
@asadsiddique5527
@asadsiddique5527 Жыл бұрын
Hay Jack, can you tell me how are your printing array values just before it?
@MarkDekkersLife
@MarkDekkersLife 2 жыл бұрын
I love your teaching even more than your music. Thanks Macklemore!!
@jherr
@jherr 2 жыл бұрын
What, what, what ... what?
@burgasdragonheirsilentgods
@burgasdragonheirsilentgods 2 жыл бұрын
Amazing !
@mani8586
@mani8586 2 жыл бұрын
Perfect video for Reduce...the mother of all functions 😅
@ryosukekureha4873
@ryosukekureha4873 2 жыл бұрын
잭 형 최고!
@nkrpradhan
@nkrpradhan 2 жыл бұрын
You are too good Jack!! The way you have compared all the array functions with reducer. Reduce indeed can replace most of the array functions which helps in grasping the concepts. Thanks. What vs extension you are using to see the output on the vscode screen?
@jherr
@jherr 2 жыл бұрын
Quokka
@nkrpradhan
@nkrpradhan 2 жыл бұрын
@@jherr Thanks, Jack. Your videos add a lot of depth to my knowledge.
@vigyanhoon
@vigyanhoon 2 жыл бұрын
No doubt reduce is mother of all but it is also mother of all complex looking code too! :)
@jeyosman1
@jeyosman1 Жыл бұрын
what extention are you using to see the values live?
@ahmedmuhammedelsaid5345
@ahmedmuhammedelsaid5345 2 жыл бұрын
the best ever
@GurbyTheGreat
@GurbyTheGreat 2 жыл бұрын
The problem with reduce is that unless the function inside is extremely simple, readibility is sacrificed. You are better off using for...of or for...in
@aksyonov100
@aksyonov100 2 жыл бұрын
Nice video Jack as usually! As you said reduce should be used with caution, don't just use it everywhere because it's cool. Good example with lookup, complexity with for-of is O(n) but with reduce you will get O(n^2) .
@jherr
@jherr 2 жыл бұрын
Not sure about that since the object by key lookup is O(1)
@aksyonov100
@aksyonov100 2 жыл бұрын
@@jherr spread operator is O(n). Every iteration you create a new object and copy everything with spread operator. You can try it on 10000 elements
@jherr
@jherr 2 жыл бұрын
@@aksyonov100 fair enough. You could just do a direct assignment. So I just chose O(n^2) in my implementation. 😂
@aksyonov100
@aksyonov100 2 жыл бұрын
@@jherr It's quite common mistake and I blame redux for that :-)
@jherr
@jherr 2 жыл бұрын
@@aksyonov100 thank you for keeping me honest. :)
@maenam4520
@maenam4520 5 ай бұрын
This reduces JavaScript in a one shoot ! From where you’ve got resources to make this crazy content 😀?
@raresraulea5455
@raresraulea5455 2 жыл бұрын
Hi, Jack. On your last example (the reduce hack), two questions: 1. How come that we are also getting the last id resolved? When we are on index 0, value 10, we are awaiting for Promise.resolve() defined as the starting accumulator, at index 1 and value 20, we are awaiting for resolved id 10 returned from first iteration and on the last index 2 with value 30 we are awaiting for the resolved id 20 returned by the promise from the second iteration. So where is the await for the last Promise executed? Does reduce use iterators behind the hood, and awaits the last promise from the accumulator when the iterator has value: undefined and done: true? 2. What is the difference of initialising the accumulator with new Promise() or Promise.resolve()? Also in this chapter, whats the difference between resolving a promise with provided resolve method (from the parameters) and using the static method of the Promise class? Thanks a lot!
@jherr
@jherr 2 жыл бұрын
Yeah. Noticed that late. I think you should await the reduce itself.
@jherr
@jherr 2 жыл бұрын
I didn’t see how much there was to this question. My bad. Promise.resolve is already resolved. I think with new promise with no function it would never resolve. Still, best thing to do here is for(of). It will be more readable and maintainable.
@raresraulea5455
@raresraulea5455 2 жыл бұрын
Related to Q1: you are actually getting the output "got 30". But how come that you get it?
@jherr
@jherr 2 жыл бұрын
@@raresraulea5455 The promise resolves before the program terminates. You should await the reduce as well, my bad on that.
@raresraulea5455
@raresraulea5455 2 жыл бұрын
Ok. Thanks a lot!
@usamaimran1516
@usamaimran1516 2 жыл бұрын
What is that extension, that gives output right after function definition?
@jherr
@jherr 2 жыл бұрын
That's probably Quokka.
@Short_and_Simple
@Short_and_Simple Жыл бұрын
at 17:48, shouldn't it be index >= 0 ? Since, the slice includes the starting index. For example: const sliceReduce = (start , end) => numbers.reduce((slice, value, index) => ( index >= start && index < end ? [...slice, value] : slice ), []) sliceReduce(1,4) // [ 2, 3, 4 ]
@campeone3
@campeone3 2 жыл бұрын
i dont understand what the three dot do in the minute 08:11
@jherr
@jherr 2 жыл бұрын
That's array destructuring. It takes all the items into the array and then flattens it into, in this case, another array as a copy.
@lookingforbino
@lookingforbino 2 жыл бұрын
Which extension did you get for showing that each step is going on under the hood?
@jherr
@jherr 2 жыл бұрын
You meant the green squares on the left?
@lookingforbino
@lookingforbino 2 жыл бұрын
@@jherr I mean every time you write some logic syntax for such as array, there's always those actions indications of what happened to those arraies on the right.
@jherr
@jherr 2 жыл бұрын
@@lookingforbino Yeah, that's Quokka.
@lookingforbino
@lookingforbino 2 жыл бұрын
@@jherr Thanks for sharing
@vigyanhoon
@vigyanhoon 2 жыл бұрын
I see the result same when I used || instead of ??. Whats the diff between them. This is for time 12:48
@jherr
@jherr 2 жыл бұрын
|| checks null-ish values (null, undefined, 0, etc.) where ?? checks against null and undefined specifically and only.
@tarekmagdy5775
@tarekmagdy5775 Жыл бұрын
why i dont understand this reduce at all :(
@mostafakheder7721
@mostafakheder7721 2 жыл бұрын
i think reduce is not the mother of all array method it is here mother in low >>>> its complicated
@jherr
@jherr 2 жыл бұрын
Hahaha mother-in-law. I love it.
JavaScript's Most Controversial Array Methods (Part 6)
12:20
Jack Herrington
Рет қаралды 7 М.
Mastering React Context: Do you NEED a state manager?
37:26
Jack Herrington
Рет қаралды 98 М.
Schoolboy - Часть 2
00:12
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 3,1 МЛН
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 27 МЛН
Slow motion boy #shorts by Tsuriki Show
00:14
Tsuriki Show
Рет қаралды 10 МЛН
Mom's Unique Approach to Teaching Kids Hygiene #shorts
00:16
Fabiosa Stories
Рет қаралды 37 МЛН
JavaScript Visualized - Event Loop, Web APIs, (Micro)task Queue
12:35
You're Doing React Hooks Wrong, Probably
20:11
Jack Herrington
Рет қаралды 64 М.
Haskell for JavaScript programmers
16:51
Tsoding
Рет қаралды 57 М.
5 Real Life Examples of Array Reduce in JavaScript
12:47
Mastering async code with Typescript and Javascript
39:01
Jack Herrington
Рет қаралды 77 М.
Code Splitting Made Simple
28:11
Jack Herrington
Рет қаралды 44 М.
Mastering React Memo
26:56
Jack Herrington
Рет қаралды 134 М.
Is reduce() bad? - HTTP 203
23:13
Chrome for Developers
Рет қаралды 77 М.
Mastering React's useEffect
25:20
Jack Herrington
Рет қаралды 172 М.
No const! How NOT To Give A JavaScript Talk
10:28
Jack Herrington
Рет қаралды 60 М.
Запрещенный Гаджет для Авто с aliexpress 2
0:50
Тимур Сидельников
Рет қаралды 978 М.
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 65 МЛН
Nokia 3310 top
0:20
YT 𝒯𝒾𝓂𝓉𝒾𝓀
Рет қаралды 3,8 МЛН
Хакер взломал компьютер с USB кабеля. Кевин Митник.
0:58
Последний Оплот Безопасности
Рет қаралды 2,2 МЛН