Method chaining | Asked in Navi for UI Engineer - 2 | JavaScript Interview Question - 8

preview_player
Показать описание
JavaScript Interview Question - 8 | In this video, we will see how to solve a JavaScript problem that was asked in NaVi's interview for UI Engineer - 2 role.

We have to showcase the working of method chaining by implementing the computeAmount() function that calculates and returns the value.

Get my Ebook "JavaScript Interview Guide" with 120+ solved JavaScript questions.

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

Hi Prashant,
I was able to solve this problem on my own thanks to your closure and function curry video.

Here is my solution.
const computeAmount = () => {
amount = 0

return {
crore: function(x){
amount +=
return this
},
lacs: function(x){
amount +=
return this
},
thousand: function(x){
amount += x*1000
return this
},
value: function(){
return amount
}
}
}


let total =

Thank you.

akash-kumar
Автор

You can fast forward where you are writing repetitive code. Good video

AyushRaj-jugb
Автор

Hello Prashant, Thank you for explaining with calmly and not rushing to get to the solution so fast.
I have one suggestion - please invest some amount to buy a good quality mic, it will help you to increase your engagement ratio and viewers will not get disturb, distracted while watching!

vaibhavmatere
Автор

hi prashant, we can also be done it with function currying would be more easy and short any suggestions please

salmanfisal
Автор

14:13 I didnt get the need of converting the solution to the function constructor? Can you elaborate please?
if we write computeAmount() and then chain it, its working fine, then why do we need function constructor?

husler
visit shbcf.ru