Function currying | Advance JavaScript interview question | Simplified complex problem

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


We are going to learn javascript function currying with simple examples to complex problems and going to solve step by step.

// What is Currying?
// Syntax?
// Q1: add(1)(2)(3)...()
// Q2: add(1)(2)....(n)
// Q3: add(1,2,3,4,5...)(3,4,5...)....(6)()
// Q4: add(1,2...)(3,4,5...)...(6)

html
css
react
react tutorial
angular
angular tutorial
javascript
js
js interview
javascript interview
leetcode
javascript interview prep
interview prep
interview preparation
react interview questions
tricky react interview question
tricky javascript interview question
javascript hard interview question
Javascript concepts
JS OOPS
Javascript Object Oriented Programming
How OOPS works in Javascript
Prototypes in JS
Javascript _ptoto_
What is a prototype in Javascript
Basics of JS
How to learn javascript
Javascript
Javascript concepts
Frontend Engineer
Frontend Developer
Software Engineer
Software Development Engineer
How to become a frontend engineer
How much salary does a frontend developer make
What is the salary of a frontend engineer
Javascript for a frontend developer
Concepts of javascript
Bootcamp for frontend developers
Roadmap for a frontend engineer
How to get a job as a frontend engineer
How to become a frontend developer
Javascript tutorial
Javascript full course
Javascript interview questions
Javascript interview questions and answers
Salary of a frontend developer
System Design
Frontend System Design

#interview #react #reactjs #angular #javascript #js #interviewprep #prepration #faang #maang
Рекомендации по теме
Комментарии
Автор

function add(...a) {
let sum = a.reduce((acc, cur) => acc + cur)

let temp = function (...b) {
if (b.length === 0) {
return sum
} else {
let sum1 = b.reduce((acc, cur) => acc + cur)
return add(sum + sum1)
}
}

temp.toString = function () {
return sum + ''
}

return temp
}

console.log(add(1, 1, 1)(1, 1, 1)(1));

kunalrathor
Автор

hi good content keep going - but I have a problem with second example it works on "jsbin" but on it doesn't work on my chrome console

jamalamrins
Автор

function add(a) {
const temp = function (b) {
if (b != undefined) {
return add(a + b);
} else {
return a;
}
};
temp.toString = () => a + "";
return temp;
}
console.log(add(3)(2)(1));

jamalamrins
Автор

I followed the same steps as Q2 to solve Q4, but somehow it's not working. Can someone point what's wrong here?
function add(...a) {
const sum1 = a.reduce((acc, curr) => acc + curr);
const fn = function (...b) {
if (b.length !== 0) {
const sum2 = b.reduce((acc, curr) => acc + curr);
return add(sum1 + sum2)
}
else {
return sum1;
}
}

fn.toString = () => {
return sum1;
}

return fn
}

console.log(add(1, 2, 3)(4, 5)(6, 7))

gyanendra_chaubey