Exercises: Array Reduce - Javascript In Depth

preview_player
Показать описание


Chapters:
00:00 Introduction
00:19 Warmup Exercise
02:58 Exercise 1
13:28 Exercise 2
17:23 Exercise 3
24:34 BONUS Exercise
33:40 Next Steps

Рекомендации по теме
Комментарии
Автор

Passing these exercises feels so good, I seriously think I’m retaining more with this playlist than I did with my Udemy course. This is saint-work. Thank you so much.

tomboolery
Автор

I was pounding my head against the wall when it kept printing the "A's". OMG! case sensitivity! I love it when things click! Love your channel, and thank you so much for these videos, Nader :D

saroebe
Автор

Thanks a lot Nader for translating programming into English. It makes so much sense to me now. In addition, the passion you show explaining the simplest outcome, which for most teachers/programmers mean nothing at this level moving at a speed of light. For us, beginners, it is so encouraging. I’m full of gratitude for your work.🙏

X-iOTube
Автор

Hi, Nader! I love love love what you do! Found your channel thanks to the mock interview video, and now I'm watching one video a day from the very beginning. Hope to catch up in a couple of months. Very solid, kind and patient explanations of the basics, fun exercises. Please, keep going, I'm a huge fan.

NadezhdaMemelova
Автор

I usually never comment on youtube videos, but i really wanna thank you for your videos! I was completly stumped onf m!p, filter and reduce and in 2 days i watched all your videos on it and could do the excercised withour seeing your solucions before solving, all thanks to your clear explanation and the well though increase in difficulty in each excercise

snowboardroks
Автор

Hey Nader, I love your style of teaching its so intuitive. Been going trough this playlist to refresh my knowledge of JS and to learn new stuff. I hope your channel grows because you really deserve it. Can't wait to go trough DOM videos and for the React series. 🤗

relja_
Автор

I enjoy the progressive structure of each exercise and how you bring bits of the previous exercise forward. This really helps the viewer pick up on the pattern in functional methods within arrays. Thankyou Sir.

nguyennguyen-nmoq
Автор

On the bonus exercise, this (literally "this", they keyword) worked for me, with the same result:

const nums = [10, 30, 50, 70, 90]

.map((num) => {
return num ** 2
})

.filter((num) => {
if (num > 1000) {
return this
}
})

.reduce((result, num) => {
return result + num
}, 0)

console.log(nums)

I just impressed myself cause I just threw the keyword there for intuition, I just thought it would make sense!

randerins
Автор

So many thanks for creating such an insightful lesson!

senniagordinskaya
Автор

For excercise 1 with the code result you provided, if you add a string that starts with "a" as the last element of the companies array, then the "-" will still show up at the end of the returned value from the recude function

Pharizer
Автор

In the first exercise, the bonus part I used .slice(0, -1) and it has the same result. Not sure if that was correct but I thought I'd mention it because I founded a bit easier than using a third parameter (i) 😀

brians
Автор

Bonus exeprices:-
const num = [10, 30, 50, 70, 90]
const squ = num.reduce(((acc, curr)=>{
let s = curr *curr ;
if(s>1000){
acc.push(curr*curr);
}
return acc;

}), [])
console.log(squ);

mitesh
Автор

const nums = [10, 30, 50, 70, 90]
.map((num) => num * num)
.filter((square) => square > 1000)
.reduce((sum, square) => sum + square)

I just enjoy using the shortened versions of arrow functions 🤩

OXIDE-isgs
Автор

The bonus exercise can be done with reduce only.

const solution = [10, 30, 50, 70, 90].reduce((result, num)=>{
num_squared = num * num;
if(num_squared > 1000){
return result + num_squared;
}
return result;
}, 0);
console.log(solution);

relja_
Автор

as a not a native English speaker, I misunderstood the 2nd exercise. Then after watching how you solved the task, I understood that the term "a sum" actually means all the array-items put together...

ab_semi
Автор

Thanks again! Quick Q:

For the bonus exercise (not bonus bonus, just bonus, haha). I had this included:

const over1000 = squares.filter((squared) => {
return squared > 1000;
});

but you had:

const over1000 = squares.filter((squared) => {
if (num > 1000) {
return true
}
return false;
}

Is yours better?

JoeMilneEnglish
Автор

For exercise 2 this is how i did it, i got a few decimal places less than yours though:



const prices = [1.23, 19.99, 85.2, 32.87, 8, 5.2];

const afterTax = prices.reduce((accumulator, index) => {
if(prices <6){
return prices;
}
if(prices > 6){
return prices *1.2;
}
return accumulator + index;

}, 0);


console.log(afterTax);

hassanegal
Автор

Great set of exercises as always! For exercise 1, I found an edge case when the last element starts with a, so I thought I'd just exclude the last -element- character ;)


const modded = companies.reduce((acc, company) => {
if (!company.startsWith('a'))
return acc + company + "-";
return acc;
}, "").slice(0, -1);

siancalebdomasig
Автор

I try it by only Capitalizing the 1st letter.
const items = ['light', 'banana', 'phone', 'book', 'mouse'];
const caps = items.map(items => {
// return items[0].toUpperCase() + items.slice(1);

React_Media
Автор

i do not understand the exrcise 1 can anybody explain me

anshsaryal