Javascript Interview Questions ( map, filter and reduce ) - Polyfills and Output Based Questions

preview_player
Показать описание
#JavascriptInterview #Javascript #FrontendInterview

Javascript Interview Questions on map, filter and reduce will be discussed in this video Pollyfills and Output Based Questions for them.

🟦 Follow me on Twitter and u will clear your interview 🤓 -

⭐ Support the channel and learn from me One on One -

🔗 Javascript Interview Series -

🔗 Cars24 Interview Experience -

🔗 Unacademy Interview Experience -

🔗 MERN Stack Tutorial with Redux -

🔗 React Beginner's Project Tutorials -

-------------------------------------------------------------------------

00:00 Intro
06:38 Polyfill for map()
09:30 Polyfill for filter()
11:31 Polyfill for reduce()
14:17 map vs forEach
16:55 Output Based Questions
17:10 Ques 1 - map
19:01 Ques 2 - filter
20:00 Ques 3 - multiple filter condition
20:47 Ques 4 - reduce
21:54 Ques 5 - Chaining map and filter
23:22 Ques 6 - Chaining map, filter and reduce
26:01 Complete Interview Playlist

-------------------------------------------------------------------------

Special Thanks to our members -
Srinivas Ayyagari
Рекомендации по теме
Комментарии
Автор

Want to thank you 😊 .. got selected at Paytm ( ur js interview questions helped a lot)

arghyamitra
Автор

the last question can be done only using reduce Because when we chain multiple operators we increase the complexity. Thanks for the video, learned alot.

let output =students.reduce((acc, curr, i, arr)=>{

if(curr.marks<60){
curr.marks+=20;
}
console.log(newMarks)
if(curr.marks>60 ){
acc=acc+curr.marks
}
return acc;
}, 0)
console.log(output);

ankittyagi
Автор

I think the best content on javascript ever on YouTube because you just don't teach theory but also the potential questions to be asked related to them. Please complete this interview playlist of javascript and don't stop making videos . Waiting for your prototype and inheritance video

pearldanish
Автор

You are the most underrated JS content creator. Thanks for your awesome contents!

susmitobhattacharyya
Автор

Good concept. Liked the way you broke down problem and showed approach to resolve it.

Also, there is one more difference between forEach and map. If element is undefined then map will skip that iteration where as forEach won’t skip that.


I found this issue when I ran new Array(3).map(cb) here map function didn’t work at all. That’s where I came across this issue.

PS: fix for above issue is
const res = new Array(3).fill(1).map(cb) 👻

shashanksshetty
Автор

Great video! Just that reduce prototype should not be checked against accumulator to assign initial value, instead should be checked for accumulator value being undefined or not . So that if you do console.log([0, 2, 3].myReduce((acc, curr)=>{return acc*curr}, 0)); you will get 0 not 6.

AkhilendreRawat
Автор

you could use "quokka extension" to log the values in vs code itself

mohammedashraf
Автор

very nicely explained the concepts with exercises....awesome!!!!keep sharing such content!!

kanchanmatai
Автор

hey, this polyfill for reduce is not giving correct result when we have to find sum of square of array items. for that we gave initial value as 0, so in for loop when we are checking accumulator has value or not it takes zero is false value assigned the value of first index instead of square of it. to removed this Error we have to refactor our ternary operator checking by
: cb(accumulator, this[i], i, this);
so when initial value is given as zero that time it will not take this as falsy value and call the callback function instead assigning first index value.

somnathnavale
Автор

U are making me stronger than my past. Love u brother..

RahulKumar-ewqw
Автор

your all videos are Praiseworthy💯. I Improved a lot after watching your tutorials 😍.. tons of thanks and respect🙏

arundhathimenon
Автор

in custom reduce function we can simply add default value to initialValue, it's cleaner and more understantable

Great content though!

Array.prototype.myReducer = function(callback, initialValue = this[0]) {
let result = initialValue;
for(let i = 0; i < this.length; i++) {
result = callback(result, this[i], i, this)
}
return result
}

theempire
Автор

Hello, you did a very good job posting these JS interview questions!

jonecir
Автор

Awesome video, thank you for sharing your expertise on map, filter, and reduce polyfills. The explanations and examples were very clear and helpful. I appreciate the effort you put into creating such a valuable resource for JavaScript interview preparation. Keep up the great work!

kalukalu
Автор

i see on issue in the reduce method polyfill that if we send 0 as the initial value, this implementation breaks due to nullish coalescing since it takes 0 as a falsy value
so we can update the check like acc = acc || acc== 0 ? cd(params): this[index]

VimalKumar-tsxn
Автор

Thanks for the videos man, using them a lot to help prepare for interviews. One flaw I found with your reduce polyfill, though, is that you need to check if the accumulator has a value of 0 first. Normal reduce lets you pass in a value of 0 to start, but if you just check for truthiness 0 will evaluate to false. I discovered this when testing my own reduce method on your problem at 20:50 . It returned [object Object] because it was taking the this[i] value as one of the objects of the array. A minor detail though, thanks again!

jenso
Автор

For reduce polyfill, we should only check if accumulator is undefined when i=0. We should not use ? To check undefined. See the output by giving [-1, 1, 2, 3]

kotireddy
Автор

Thank you For This.

PS: In last question, Inside map you modified the original students.

GauravKumar-uenz
Автор

Love you from Pakistan 🇵🇰 I got a remote job in the US your videos helped me a lot

randomsVlogs
Автор

Better solution for last Question : -

const result = students
.map((stud) => (stud.mark < 60 ? { ...stud, mark: stud.mark + 20 } : stud))
.reduce(
(accu, curStudent) =>
curStudent.mark > 60 ? accu + curStudent.mark : accu,
0
);

Reason why is this solution better : -
1st reason : you save using Filter method means more optimized .
2nd reason : The solution provided in video at 24:32, he mutates the stu.mark += 20 which in result also mutates the original array(students) which is bad practice.

uxtomxn