Javascript Interview Questions ( Currying ) - Output based Questions, Partial Application and more

  Рет қаралды 75,459

RoadsideCoder

2 жыл бұрын

#JavascriptInterview #Javascript #FrontendInterview
Javascript Interview Questions on Currying will be discussed in this video including topics like Infinite currying, curry() implementation, Partial Application, Output based Questions etc.
🟦 Follow me on Twitter and u will clear your interview 🤓 -
piyush_eon
⭐ Support the channel and learn from me One on One -
kzbin.info/door/IPZVAwDGa-A4ZJxCBvXRuQjoin
📖 Blog for this video -
roadsidecoder.hashnode.dev/javascript-interview-questions-currying-output-based-questions-partial-application-and-more
🔗 Closures Video -
kzbin.info/www/bejne/qYvNnXiBl8asocU
🔗 Javascript Interview Series -
kzbin.info/aero/PLKhlp2qtUcSaCVJEt4ogEFs6I41pNnMU5
🔗 Cars24 Interview Experience -
kzbin.info/www/bejne/rKnKmI2cm7Skm80
🔗 Unacademy Interview Experience -
kzbin.info/www/bejne/l5PFlX1qjsuga5Y
🔗 MERN Stack Tutorial with Redux -
kzbin.info/www/bejne/f4K7m4JmqZmLiK8
🔗 React Beginner's Project Tutorials -
kzbin.info/aero/PLKhlp2qtUcSa_rX7glmB7HyFsEOEQa0Uk
-------------------------------------------------------------------------
00:00 Intro
00:15 What is Curring in Javascript?
00:53 Example of Currying
03:04 Why Currying?
03:37 Ques 1 - Implement sum(2)(6)(1)
06:22 Ques 2 - Reusing Variable for logic
09:29 Ques 3 - Infinite Currying
13:47 Ques 4 - Currying vs Partial Application
15:57 Ques 5 - Manipulating DOM
18:22 Ques 6 - curry() implementation
24:22 Read the blog for this video
-------------------------------------------------------------------------
Special Thanks to our members -
Srinivas Ayyagari

Пікірлер: 108
@AmanSingh-qr3ld
@AmanSingh-qr3ld 2 жыл бұрын
You are putting so much effort to make such topics easy for us. Thanks for putting content like this. We really appreciate it.
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
❤️❤️ Thank you so much, greatful
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
Correction for the last question - At 22:15 args.length is 1, which of course it is, then I said length of function is 4, and highlighted the four curried functions at line number 22. Which is kind of not the case here, Here, func is that sum function I passed as prameter to original curry function and func.length would be length or number of parameters that func (sum function) expects. Which in this case sum function expects four formal parameters which are: a, b, c, d. So four comes from here, not from the curried functions in line 22. Sorry for the explanation gap.
@adityanarayangantayat7133
@adityanarayangantayat7133 2 жыл бұрын
Exactly what I was going to comment and ask! Glad to find your comment 😅
@adimaralimuddin96
@adimaralimuddin96 Жыл бұрын
it was the length of the first argument as callback function on the first call. if the arg.length == curryArg.length ? then only call the callback function.. this one is actually very usefull.
@amansaxena4446
@amansaxena4446 Жыл бұрын
you should also explain this The length data property of a Function instance indicates the number of parameters expected by the function. for some folks it could be possible they couldnt understand how func.length is coming
@abhirocks723
@abhirocks723 8 ай бұрын
yes... by the way thank you for explaining
@rajkishorshaw2379
@rajkishorshaw2379 Жыл бұрын
Currying is a function that takes one argument at a time and returns a new function expecting the next argument. It is a conversion of function from callable as f(a,b) to f(a)(b).
@woongda
@woongda Жыл бұрын
this is one of the coolest thing I learn !! I have all those chained http post calls, now I can do post(data1)(data2)(data3)((res) => { something}) without using promise and async/await and at the same time, no callback hell. I can throw error and use try/catch like async/await does.
@A1996ARP2075
@A1996ARP2075 2 жыл бұрын
Great next make on OOPS concept and prototype related
@pushpabhandari619
@pushpabhandari619 2 жыл бұрын
Thank you sir, your video's is really helpful please continue this interview series
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
Yes, More on the way!
@arjobansingh1940
@arjobansingh1940 2 жыл бұрын
Great video, but i guess it was slightly confusing when you said, func.length. At 22:15 you said args.length is 1, which of course it is, then you said length of function is 4, and highlighted the four curried functions at line number 22. Which is kind of not the case here, Actually here func is that sum function you passed as prameter to original curry function and func.length would be length or number of parameters that func (sum function) expects. Which in this case sum function expects four formal parameters which are: a, b, c, d. So four comes from here, not from the curried functions in line 22. As according to MDN, length is a property of a function object, and indicates how many arguments the function expects, i.e. the number of formal parameters. This number excludes the rest parameter and only includes parameters before the first one with a default value. Nonetheless great video!
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
Yes, my bad.. That was a little gap in my explanation, I'll add a pinned comment for correcting this part.
@arjobansingh1940
@arjobansingh1940 2 жыл бұрын
@@RoadsideCoder Cool!
@chaitanyayash2958
@chaitanyayash2958 Жыл бұрын
Brother, you are a gem. Thank you so much.
@karthikk1098
@karthikk1098 Жыл бұрын
Thank you so much for educating and your videos were super mind game. I know you are intended to communicate in simple English and react language. Since I am a beginner in JS, just excited to share this the one n only question I solved better. const arithOp = { add: "+", subtract: "-", divide:"/", multiply:"*" } function one(type){ return function(lhs){ return function(rhs){ const resultString = `lhs ${arithOp[type]} rhs`; console.log(eval(resultString)); } } } one("add")(3)(3);
@RoadsideCoder
@RoadsideCoder Жыл бұрын
Awesome! Thanks for adding this approach here
@RahulKumar-ew1qw
@RahulKumar-ew1qw 2 жыл бұрын
Now , watching this type of video, lets hit the interview.. You are best of best .. ,🔥
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
All the best 😎🔥
@fishamit
@fishamit 8 ай бұрын
i believe that your example for the "curry" function allows for passing multiple arguments in each subsequent invocation of a curried function. Isn't it more accurate to allow only one argument in each curried call? by removing the rest and spread operators on "next", on lines 11 + 12. 24:16
@dailyPractice1
@dailyPractice1 Жыл бұрын
The best thing about this series is that "You are covering questions topic wise in each separate video", So we can say we covered few question on this or that topic.
@RoadsideCoder
@RoadsideCoder Жыл бұрын
Glad it helped you!
@kartikkaushik4743
@kartikkaushik4743 10 ай бұрын
Nice effort earlier I though it used to be a cuury made inside the kitchen only but in js how to used with the function its great ,brother you are great
@hemantpratapsingh236
@hemantpratapsingh236 2 жыл бұрын
This is gold ... 👍👍 Such a quality content . .. keep going brother...
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
🙏🙏
@MrCoder-u9y
@MrCoder-u9y Жыл бұрын
Deserve a million subscribe
@RoadsideCoder
@RoadsideCoder 7 ай бұрын
🔴 Get my Complete Frontend Interview Prep course - roadsidecoder.com/course-details
@ramuramu8910
@ramuramu8910 2 жыл бұрын
Thanks for u r video with clear explanation.
@rahularora9153
@rahularora9153 Жыл бұрын
Great Work bro, keep it up
@RoadsideCoder
@RoadsideCoder Жыл бұрын
Thanks 🔥
@gkinfos
@gkinfos 2 жыл бұрын
in question 5- Manipulating Dom we can get the ref of element in one variable and then keep on updating the content, so why curring adding more sense here?
@pravinjohannes7699
@pravinjohannes7699 2 жыл бұрын
Thank you so much sir, it is very much helpful and all your videos have helped to understand the javascript very well especially all your interview videos sir, thank you so much sir
@achyutkumarsingh7308
@achyutkumarsingh7308 4 ай бұрын
Thanks for teaching a new concept
@Jatindamariya
@Jatindamariya 4 ай бұрын
Isnt question 5 (dom manipulation) here an example of using closures instead of currying? How does currying link to this question?
@ankushladani496
@ankushladani496 2 жыл бұрын
Great Quality Content....
@AbhinashKumar-ql3tn
@AbhinashKumar-ql3tn 2 жыл бұрын
impressive teaching methodology..
@journeycalculated
@journeycalculated Жыл бұрын
in my first call the Hr asked me waht web application do you use....i was noy aware what web applications are...? could you explain me
@dev-suresh
@dev-suresh 5 ай бұрын
Super useful video. Thanks
@engsmyle
@engsmyle 2 жыл бұрын
Thanks you for explaining it very well, I really understand it now 😅...
@Karansingh_78
@Karansingh_78 Жыл бұрын
sir i have a doubt in console.log(add(2)(3)(4)); when remove the last parenthesis it showing output as function [anonymous] , sir what will be reason?
@BalajiAade-bm7go
@BalajiAade-bm7go 7 ай бұрын
Bhaiya please reply in timestamp 15:58 actually I think the example you provide is actually behave like a closure not currying tell me if i am wrong
@siddesh1210
@siddesh1210 Жыл бұрын
Interview has asked me so its become more difficult to write function if we use currying so why we are using it like : function add(a,b,c){ return a+b+c; } And same if we do currying it will take 2 internal function and than it will return us value. So bhaiya how should we answer this questions??
@merakshay7623
@merakshay7623 Жыл бұрын
Hey piyush there is catch in function add(a){ return function(b){ if(b) return add(a+b) return a; } } example console.log(add(10)(0)()); if b = 0 then it does not return any function so its throw an error called TypeError: add(...)(...) is not a function here is a proper solution function add(a){ return function(b){ if(b !== undefined) return add(a+b) return a; } } thank you _/\_
@MrCoder-u9y
@MrCoder-u9y Жыл бұрын
Great buddy
@merakshay7623
@merakshay7623 Жыл бұрын
@@MrCoder-u9y thanks
@TanmayKamath
@TanmayKamath 11 ай бұрын
This time in Cars24 i was asked this question. You need to curry add if n number of arguments are placed in any manner after the function: sum(1)(2)()()()(3)
@SIVAREDDY-e4l
@SIVAREDDY-e4l 11 ай бұрын
Only if the last argument is empty we can go for Infinite currying as the tutorial explained if the middle argument is empty it stops there itself and gives result. Anyway what was the answer you gave and how can we solve this problem?
@TanmayKamath
@TanmayKamath 11 ай бұрын
@@SIVAREDDY-e4l Yes using recursion, you have to check whether the arguments is equal to the function length.
@shubamdadhwal3497
@shubamdadhwal3497 Жыл бұрын
Loved the video bro, although i think there is no need to do: 1. the rest and spread of next arguement 2. greater condition check i.e. (args.length >= func.length) OR correct me, if i m wrong somewhere function curry(func) { return function curriedFunc(...args) { if (func.length === args.length) { return func(...args); } else { return function (next){ return curriedFunc(...args, next); } } } }; Also for those who don't know - function.length -> returns the EXPECTED number of arguments a function is expecting excluding the default and rest parameter arguments.length -> returns the ACTUAL number of arguments passed to a function
@praveengautam4689
@praveengautam4689 Жыл бұрын
thanku for function.length explaination
@debabratamukherjee9577
@debabratamukherjee9577 11 күн бұрын
Good Point 👍👍 But if i do not spread the next argument, the following function will not work --> curriedSum(1)(2,3); Hope you understand.
@rahul.sarkar
@rahul.sarkar 2 жыл бұрын
Please make a video on throttling and debouncing in JavaScript 🥺🙏
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
Yes that's in the way!
@raammeena6650
@raammeena6650 2 жыл бұрын
Really appriciate you content
@master_coder8628
@master_coder8628 2 жыл бұрын
Love your videos. 💙 Please bring fast too
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
Thank you!
@Lavith_kuttu
@Lavith_kuttu Жыл бұрын
When the interviewer asked us to write a function for multipler6 (if I have given 3 it should return 18, if 6 then 36 ) this is called partial application. const mul = (a=6) => { return (b) => { return a * b; }; }; const mul6 = mul(); console.log(mul6(3)); console.log(mul6(13)); console.log(mul6(9));
@anubhavmahajan230
@anubhavmahajan230 2 жыл бұрын
The last question was epic 🤟
@gagansuneja7029
@gagansuneja7029 4 ай бұрын
My answer for currying function sum(args){ if(args == undefined) { let currentSum = sum.currentSum; sum.currentSum = 0; return currentSum; } sum.currentSum = (sum.currentSum || 0) + args; return sum; }
@atharshakeel7277
@atharshakeel7277 2 жыл бұрын
Great video and very well explained
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
Thanks ❤️
@akshitatyagi5234
@akshitatyagi5234 2 жыл бұрын
So we will need to pass () as blank to stop the recursion in 13:31 otherwise the output is always a function . Is there any way we can do this without adding empty () in the end??
@dkatorzaify
@dkatorzaify 2 жыл бұрын
Hi, you don't need to pass () as blank. What will stop the recursion is the "if" statement once it will be true, meaning once the number of args will match the number of functions.
@akshitatyagi5234
@akshitatyagi5234 2 жыл бұрын
@@dkatorzaify If u will quickly run this in browser console, you can see it is always returning a function. Logic seems okay but its not working, without the ()
@dkatorzaify
@dkatorzaify 2 жыл бұрын
@@akshitatyagi5234 This is strange... I copied this to the console and it does work. function curry(func) { return function curriedFunc(...args) { if(args.length >= func.length) { return func(...args) } else { return function(...next) { return curriedFunc(...args,...next); } } } } const sum = (a,b,c,d) => a+b+c+d const totalSum = curry(sum) console.log(totalSum(1)(2)(3)(4))
@akshitatyagi5234
@akshitatyagi5234 2 жыл бұрын
@@dkatorzaify I am talking about the example at 13:31
@DineshVutukuru
@DineshVutukuru 2 жыл бұрын
07:48, you can use Switch case. It's little better than nested If else loops.
@saipratapdannana8048
@saipratapdannana8048 2 жыл бұрын
How much can we demand as front end developer with 1 year experience?
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
Minimum 15 LPA
@gurmandeep4417
@gurmandeep4417 2 жыл бұрын
Can u please tell how to solve a error while making a project
@kritigoel3854
@kritigoel3854 2 жыл бұрын
Hi @RoadsideCoder , with infinite currying code, its returning only Function ..not the addition, Could you please clarify. function add(a){ return function(b){ if(b) return add(a + b); return a; } } console.log(add(4)(5)(7)); OUTPUT: [Function]
@sandyGamer97
@sandyGamer97 2 жыл бұрын
it is returning function because you should call like this console.log(add(4)(5)(7)()) ; without (), function does not get invoked and you get only function body
@pkyadav6230
@pkyadav6230 8 ай бұрын
Subscribed❤
@lifeisbeautifu1
@lifeisbeautifu1 Жыл бұрын
Thank you
@Abhishekverma-yj1or
@Abhishekverma-yj1or 2 жыл бұрын
My Interview asked me this question -> Write a function sum that takes n arguments and can be called n times. Note - Function can take n arguments and can be called n times. For example - sum(1,3,5,1)(1,2,3,4,5)(1)(1,2)(1,1,1,1,1,1)(1,4,5)(12)(11)(50, 51, 52) console.log(sum.....) => 221 It was for SDE - 1 Role. I still not able to understand this problem.
@Abhishek_Sawant
@Abhishek_Sawant 2 жыл бұрын
const infiniteSum = (...a) => { return (...b) => { const currSum = [...a, ...b].reduce((sum, val) => sum + val, 0); return b.length ? infiniteSum(currSum) : currSum; }; };
@Abhishekverma-yj1or
@Abhishekverma-yj1or 2 жыл бұрын
@@Abhishek_Sawant Hey thanks man :)
@Abhishek_Sawant
@Abhishek_Sawant 2 жыл бұрын
@@Abhishekverma-yj1or 👍😅
@sandyGamer97
@sandyGamer97 2 жыл бұрын
function sum(...args){ let a = args.reduce((a,b)=>a+b,0); return function (...args){ let b = args.reduce((a,b)=>a+b,0); if(b) return sum(a+b); return a; } }
@kashmirtechtv2948
@kashmirtechtv2948 3 ай бұрын
In manipulating DOM example, why don't we simply create a fucntion instead of returning a fucntion
@Frank-vm7vm
@Frank-vm7vm 2 жыл бұрын
Bhai Make video on spread operator tricks
@biswajitchanda6592
@biswajitchanda6592 11 ай бұрын
const sum = function(a) { return function(b) { if (b) { return sum(a + b); } else { return a; } } } yes we can write that in one line: const add = a => b => b ? add(a + b) : a;
@pavithrasai1392
@pavithrasai1392 2 жыл бұрын
how much can we demand for frontend developer role with 3.9 yrs of experience?
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
Depends on your skills, sky is the limit.
@pavithrasai1392
@pavithrasai1392 2 жыл бұрын
​@@RoadsideCoder I have experience and knowledge in JS, ReactJS and React Native
@HemantKumar-dl9wh
@HemantKumar-dl9wh 2 жыл бұрын
Hi, I've written below code. Is it write wrt to currying?' const evalute = a => { switch (a) { case 'sum': return function (b) { return function (c) { return b + c; }; }; case 'sub': return function (b) { return function (c) { return b - c; }; }; default: break; } }; console.log(evalute('sum')(5)(3)); console.log(evalute('sub')(5)(3));
@ashishprasad2163
@ashishprasad2163 Жыл бұрын
Follow dry(Don't Repeat Yourself)
@kewalkandpal
@kewalkandpal 2 жыл бұрын
🔥🔥🔥
@akash_gupta_2090
@akash_gupta_2090 Жыл бұрын
done ... !
@NirajKumar-j4m4r
@NirajKumar-j4m4r 2 ай бұрын
This will give you an error when you pass b=0 to handle all cases use below code function add(a) { return function (b) { return b >= 0 ? add(a + b) : a; }; } console.log(add(1)(2)(4)(0)());
@santrawebtech35
@santrawebtech35 2 жыл бұрын
how are you sir please make a project on MERN as like dosti chat app
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
Sure :)
@santrawebtech35
@santrawebtech35 2 жыл бұрын
@@RoadsideCoder thanks love you sir
@kashmirtechtv2948
@kashmirtechtv2948 3 ай бұрын
Now i am confused between Closure and Currying 😅
@eelguneezmemmedov1671
@eelguneezmemmedov1671 Жыл бұрын
Please put the on github sir .
@ambupadamuduli3794
@ambupadamuduli3794 2 жыл бұрын
Bro jaldi jaldi video daalo
@Cuddlehead
@Cuddlehead 7 ай бұрын
*okay cool*
@anushajammula9837
@anushajammula9837 2 жыл бұрын
I want theory related and code based questions with pdf
@RoadsideCoder
@RoadsideCoder Жыл бұрын
Sure, I'll create a github repository for it!
@jaisharma545
@jaisharma545 2 жыл бұрын
now legends will only subscribe you because of "69" years of goodluck 🤣
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
Are u that legend?
@jaisharma545
@jaisharma545 2 жыл бұрын
@@RoadsideCoder yes I am😂 and thank you from the depth of my heart. for creating such awesome content 💙
@RoadsideCoder
@RoadsideCoder 2 жыл бұрын
@@jaisharma545 welcome 🙏
@vishalmishra1937
@vishalmishra1937 Жыл бұрын
0:31 🤣
@bhushanbhale3309
@bhushanbhale3309 Жыл бұрын
Why 69 years of goodluck..... means why 69 only 😁😁😁
Ozoda - Lada ( Official Music Video 2024 )
06:07
Ozoda
Рет қаралды 30 МЛН
Mom had to stand up for the whole family!❤️😍😁
00:39
didn't manage to catch the ball #tiktok
00:19
Анастасия Тарасова
Рет қаралды 32 МЛН
How I Turned a Lolipop Into A New One 🤯🍭
00:19
Wian
Рет қаралды 10 МЛН
Ozoda - Lada ( Official Music Video 2024 )
06:07
Ozoda
Рет қаралды 30 МЛН