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

preview_player
Показать описание
#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 🤓 -

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

📖 Blog for this video -

🔗 Closures Video -

🔗 Javascript Interview Series -

🔗 Cars24 Interview Experience -

🔗 Unacademy Interview Experience -

🔗 MERN Stack Tutorial with Redux -

🔗 React Beginner's Project Tutorials -

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

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
Рекомендации по теме
Комментарии
Автор

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.

RoadsideCoder
Автор

You are putting so much effort to make such topics easy for us. Thanks for putting content like this. We really appreciate it.

AmanSingh-qrld
Автор

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).

rajkishorshaw
Автор

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

amansaxena
Автор

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!

arjobansingh
Автор

this is one of the coolest thing I learn !! I have all those chained http post calls, now I can do => { 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.

woongda
Автор

Great next make on OOPS concept and prototype related

AARP
Автор

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.

dailyPractice
Автор

Now, watching this type of video, lets hit the interview.. You are best of best .., 🔥

RahulKumar-ewqw
Автор

Thank you sir, your video's is really helpful please continue this interview series

pushpabhandari
Автор

Brother, you are a gem. Thank you so much.

chaitanyayash
Автор

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`;

}
}
}
one("add")(3)(3);

karthikk
Автор

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;
}

gagansuneja
Автор

This is gold ... 👍👍 Such a quality content . .. keep going brother...

hemantpratapsingh
Автор

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

kartikkaushik
Автор

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?

gkinfos
Автор

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)

TanmayKamath
Автор

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 _/\_

merakshay
Автор

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

shubamdadhwal
Автор

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

fishamit
join shbcf.ru