JavaScript Array Reduce Method Practice in 5 Minutes

JavaScript Array Reduce Method Practice in 5 Minutes

James Q Quick

3 года назад

48,030 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@user-js3nt7dk8v
@user-js3nt7dk8v - 21.12.2023 11:40

🤯🥳🥳🥳 eye color example ,and yes am a beginner

Ответить
@urbanebachelor
@urbanebachelor - 03.07.2023 21:19

Theres a great chance that things have changed in the 2 years since this video posted, but when I try to work along, I get a long string of numbers instead of the sum total:
const totalMass = characters.reduce((acc, cur) => acc + cur.mass, 0);
console.log(totalMass);
0771364984

Ответить
@user-ix6jx1wt3e
@user-ix6jx1wt3e - 12.06.2023 19:30

do u have an explanation for react plz??

Ответить
@emediongidemeto
@emediongidemeto - 24.05.2023 17:02

What's the name of your theme sir?

Ответить
@emediongidemeto
@emediongidemeto - 24.05.2023 16:19

What's the name of your font sir?

Ответить
@doniaelfouly4142
@doniaelfouly4142 - 07.03.2023 17:28

Thanks

Ответить
@chubbyBunny94
@chubbyBunny94 - 07.02.2023 17:25

Me again, I forgot it all :D

Ответить
@snapdeus
@snapdeus - 19.01.2023 23:42

nice, the biggest "aha" moment for me was realizing you can set the initial value to be an empty object

Ответить
@REET911
@REET911 - 04.01.2023 12:00

Can anyone clarify why acc[cur.eye_color] works but same with dot notation acc.cur.eye_color doesn't work??

Ответить
@robinstahlwarelius1845
@robinstahlwarelius1845 - 07.12.2022 18:21

Great videos! Thx man :)
PS color theme do you use?

Ответить
@zenguitarankh
@zenguitarankh - 15.11.2022 04:08

Not sure if maybe something in JS has changed since this video but for totalMass, I kept getting 0771364984 so I knew it was being concatenated as strings so I tried commenting out 'use strict' and also tried taking quotes off the numbers in the characters array but the only fix was wrapping cur.mass in Number() in the return. I'm sure parsint etc probably works too Just incase someone else has this problem and is spinning their wheels.

Ответить
@nested9301
@nested9301 - 21.10.2022 00:04

how can i find more challenges ? thank you!

Ответить
@tripvida
@tripvida - 23.09.2022 10:48

Well explained thanks.

Ответить
@mocococo2877
@mocococo2877 - 21.09.2022 20:31

Greetings from Bulgaria. Thank you for your time and efforts to put those wonderful tutorials.
Please, tell me in the case of eye colors, how that object got miraculously arranged into those exact key value pairs, since nowhere you specified that ?
Thank you.

Ответить
@user-xz3ws9lz1o
@user-xz3ws9lz1o - 11.08.2022 08:02

need more class

Ответить
@driftwood13
@driftwood13 - 23.06.2022 06:51

Can you show how to sort an array of strings case sensitive? e.g. Luke, leila, Darth, yoda

Ответить
@bradpeters9511
@bradpeters9511 - 15.05.2022 04:51

I gave you a thumbs up. The video is mostly clear. I wish you would have explained why you started with an empty object. With that being said I have seen several examples of using the reduce method with objects and this is one of the more clear explanations even though I do not understand why you start with an empty object.

Ответить
@ianhancock3414
@ianhancock3414 - 11.05.2022 15:07

Flawless explanations! thank you

Ответить
@capslock3250
@capslock3250 - 01.05.2022 00:20

Thanks 👍

Ответить
@JimKernix
@JimKernix - 16.03.2022 02:19

This and the map vieo were helpful - thanks! I forgot to sub to your channel when I saw your video on Brad Traversy's channel.

Ответить
@dand4485
@dand4485 - 22.11.2021 07:16

Ditto.... Sorry to sound like a broken record. But another great video ;)

Ответить
@ayodejijoseph6864
@ayodejijoseph6864 - 10.11.2021 13:25

I wonder the people giving thumbs down for this lovely easy to understand video 🤔, can we see something better from you lots giving thumbs down then.

Ответить
@dlongodesign7026
@dlongodesign7026 - 21.10.2021 23:09

The best video I found with Reduce() examples. THANK YOU SO MUCH!!

Ответить
@jaydenmoon1165
@jaydenmoon1165 - 19.09.2021 20:40

First time watching your vids - this was an easy sub for me - really love your vids and explanations - it has been helpful - thank you

Ответить
@nathanboeger978
@nathanboeger978 - 24.08.2021 18:19

Dude, over 10k views but only 579 likes? That dog won't hunt.

Ответить
@davidjohansson2372
@davidjohansson2372 - 11.08.2021 13:23

Great series on the JS array methods, thanks!

Ответить
@GabrielMazzoleni
@GabrielMazzoleni - 08.08.2021 22:36

The eye color example was really good, thanks

Ответить
@kirilvedmidskiy3661
@kirilvedmidskiy3661 - 26.07.2021 13:09

if you downloaded array from github, you should convert mass from string to number for it to work: +acc + +cur.mass

Ответить
@richcaro3132
@richcaro3132 - 25.07.2021 09:48

niced

Ответить
@chubbyBunny94
@chubbyBunny94 - 30.06.2021 14:20

Back again for a refresher; by far the most extensive tutorial on this topic

Ответить
@ctx4241
@ctx4241 - 14.06.2021 20:59

map and reduce are such bizarrely named functions...

Ответить
@drkgumby
@drkgumby - 12.05.2021 20:00

Excellent video.
Suggestion 1: Turn off vs code intellisense so the popup does not cover your code.
Suggestion 2: Put the terminal on the right
Suggestion 3: run 'nodemon worksheet.js -q' to hide nodemon status and clean up the console

Ответить
@RhoTrepaan
@RhoTrepaan - 26.04.2021 15:08

This was quicker than ‘looking it up’ thanks 👍

Ответить
@TheNamesJT
@TheNamesJT - 07.03.2021 02:57

I don't understand the eye color " if (acc[color]) " this if statement checks if color exists right? I don't understand how it decides to count the same color and don't understand the false statement either if color doesn't exist then you set color to true? this if statement is confusing.

Ответить
@bar8393gm
@bar8393gm - 27.02.2021 05:03

Just what i'm looking for. Great work. I'm a looooonnnnng time SQL programmer and new to javascript (which is my new retirement hobby). I was always wondering how in javascript to do a simple "Select EyeColour, count(*) from Characters group by EyeColor". This has opened my eyes! (Which are blue by the way if you need to add that to the data set. 😁)

Ответить
@NavilRodrigues
@NavilRodrigues - 26.02.2021 17:27

Wow! Thanks a ton. Can you please make a video on how you've customized your VS code and zsh?

Ответить
@TheLuksas
@TheLuksas - 21.02.2021 20:19

to difficult for me.. :/

Ответить
@sateeshnaidu900
@sateeshnaidu900 - 18.02.2021 10:10

Hi James Q Quick , your tutorials are simply awesome, In reduce function example the output of totalMass producing incorrect result(0497784136) , we have to apply parseInt to curr.mass i.e characters.reduce((acc, cur) => acc + parseInt(cur.mass),0). so that we will get correct result(346). Thanks for your Great Tutorials.

Ответить
@John-nr8vu
@John-nr8vu - 12.02.2021 15:56

Fuck no dislikes yet 🙄😯 is it a sign to hope in humanity again?😁

Ответить
@lovegreekhebrew
@lovegreekhebrew - 11.02.2021 14:14

Great stuff! I'll always go back to this playlist!

Ответить
@mitchell4217
@mitchell4217 - 11.02.2021 02:56

Wondering if you can return values as arrays and don't return duplicates:
{
eye_color: ["brown","blue","green"]
}

Ответить
@josesilva2614
@josesilva2614 - 06.02.2021 20:24

I just have a problem, my values are concatenate. I try with Math but nothing =(

Ответить
@henrikschmidt8178
@henrikschmidt8178 - 05.02.2021 09:43

is there a reasone not to use syntax like: arr["index"] = (arr["index"]||0) +1; to handle initialization of unused indexes to skip the if else?

Ответить
@ripplesr5655
@ripplesr5655 - 04.02.2021 15:08

Hey,i have put every bit of effort to figure out what am i doing wrong, but i am getting this number as total of mass <0771364984>.I have rechecked countless times, i have the exact same code but with different number.

Ответить
@ridl27
@ridl27 - 04.02.2021 14:00

ty

Ответить
@DhanByCode
@DhanByCode - 09.01.2021 11:23

My English is not very good but I really understand it with your explanation, I like your style in explaining and the font used is quite pleasing to the eye with an explanation and a font size that is very suitable and comfortable to see and hear, awesome .. I hope you explain more in detail like this and more tutorials about javascript on your channel cz this tutorial is great!

Ответить
@kagishophahlamohlaka2306
@kagishophahlamohlaka2306 - 07.01.2021 23:49

I LIKE YOU PJ'S!!!!! if they are pj's

Ответить
@guythesavage2908
@guythesavage2908 - 07.01.2021 20:03

I was the 69th like, nice

Ответить
@shubhsagar6234
@shubhsagar6234 - 07.01.2021 10:46

thank you so much but i have a doubt , instead of ""curr.mass'" can we write it using destructuring if yes then how?

Ответить