Currying In JavaScript

An engineer by profession and a JavaScript Lover by heart.
First and foremost, I love writing code. Ever since writing my first program in C and manipulating it to produce the desired output. I believe in the power of programming to transform and improve the lives of people around the world.
My curiosity levels are as fresh as when I was a child. I believe in eternal learning and deliberate effort as they are the only way to become the smartest in the room. I am a good timekeeper, always willing to learn new skills and use them in real-life problems.
An ambitious individual with a desire to succeed. A Cricket fanatic. A student who likes to take risks and does not shy away from experimenting with various combinations in life. Striving to do a lot. Wish me good luck ๐๐ผ
My primary interest is in Web Development and Mobile Application Development.
Tech Stack:- ReactJS, NextJS, NodeJS, MongoDB, GraphQL, Javascript Version Control:- Git, Gitlab
Currying is the process of converting a function that takes multiple arguments at once into a sequence of function's each with a single argument.
๐๐ผ๐ ๐ฑ๐ผ๐ฒ๐ ๐ถ๐ ๐๐ผ๐ฟ๐ธ?
Let's say you have a function with multiple arguments: sum(a,b,c).
๐จ๐๐ถ๐ป๐ด ๐๐๐ฟ๐ฟ๐๐ถ๐ป๐ด, ๐๐ผ๐ ๐๐ถ๐น๐น ๐ด๐ฒ๐ ๐ฎ ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป ๐๐๐บ๐ฌ(๐ฎ) ๐๐ต๐ฎ๐ ๐ฟ๐ฒ๐๐๐ฟ๐ป๐ ๐ฎ ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป ๐๐๐บ๐ญ(๐ฏ) ๐๐ต๐ฎ๐ ๐ฟ๐ฒ๐๐๐ฟ๐ป๐ ๐ฎ ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป ๐๐๐บ๐ฎ(๐ฐ).
๐๐ป ๐ฆ๐ถ๐บ๐ฝ๐น๐ฒ ๐ง๐ฒ๐ฟ๐บ๐: ๐๐๐บ(๐ฎ, ๐ฏ, ๐ฐ) โ> ๐๐๐บ๐ฌ(๐ฎ) => ๐๐๐บ๐ญ(๐ฏ) => ๐๐๐บ๐ฎ(๐ฐ)
๐๐ ๐ฎ๐บ๐ฝ๐น๐ฒ ๐
const sum = (a) => {
return (b) => {
return (c) => {
return a + b + c;
};
};
};
const sum = (a) => (b) => (c) => a + b + c;
๐๐ผ๐ ๐๐ผ ๐ฐ๐ฎ๐น๐น ๐๐ต๐ฒ ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป?
๐ฌ) sum(10)(20)(30); // 60
๐ญ) const addTen = sum(5)(5);
addTen(20); // 30