Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

currying in javascript

//Currying:
It is a technique in functional programming, transformation of the 
function of multiple arguments into several functions of a single 
argument in sequence. It is also called nested function is ecmascript

//Without currying
function calculateVolume(length, breadth, height) {
        return length * breadth * height;
    }
//With Currying
function calculateVolume(length) {
        return function (breadth) {
            return function (height) {
                return length * breadth * height;
            }
        }
    }
Comment

currying in javascript

//No currying
function volume(w, h, l) {
  return w * h * l;
}

volume(4, 6, 3); // 72

//Currying
function volume(w) {
  return function(h) {
    return function(l) {
      return w * h* l;
    }
  }
}

volume(4)(6)(3); // 72
Comment

function currying javascript

// function curring 

let num = (num1) => {
    return (num2) => {
        return (num3) => {
            console.log(num1, num2, num3);
        }
    }
}

num(10)(20)(30);


//output  =      10 20 30


//
Comment

What is currying in JavaScript

// Currying :
//- Currying is an advanced technique of working with functions.
function sum(a) {
  return function (b) {
    return function (c) {
      return function (d) {
        console.log("sun is:::", a + b + c + d);
      };
    };
  };
}
sum(5)(7)(3)(20);
Comment

currying javascript

// It is also called nested function is ecmascript
const multiply = (a) => (b) => a*b;
multiply(3)(4); //Answer is 12

const multipleBy5 = multiply(5);
multipleBy5(10); //Answer is 50
Comment

currying function callback javascript

// function curring with callBack function 

let num = (num1) => (num2) => (num3) => console.log(num1, num2, num3);
num(10)(20)(30);


//output  =      10 20 30


//
Comment

PREVIOUS NEXT
Code Example
Javascript :: react tostify 
Javascript :: object clone javascript 
Javascript :: how to find hcf of 2 numbers in javascript 
Javascript :: how to check if value is undefines if condition jquery 
Javascript :: find in array function 
Javascript :: close div when click outside angular 7 
Javascript :: javascript check type of object 
Javascript :: poo js 
Javascript :: is checked checkbox jquery 
Javascript :: node javascript foreach limit 
Javascript :: laravel send http post request json 
Javascript :: kendo template multiselect default selected 
Javascript :: javascript and operator 
Javascript :: suppress spaces in front and in the end of a string javascript 
Javascript :: javascript get same elments from multiple arrays 
Javascript :: loop through json array and get key name 
Javascript :: check if string matches a regex 
Javascript :: random letter from a name js 
Javascript :: javascript returning a function 
Javascript :: fetch Response object get content type 
Javascript :: react google map 
Javascript :: electron how to setup preload.js 
Javascript :: formdata append not working 
Javascript :: how to show progress on ajax call 
Javascript :: discord.js.Client 
Javascript :: link href javascript 
Javascript :: how to take screenshot of desktop using electron js 
Javascript :: Immediately-Invoked Function javascript 
Javascript :: sort js 
Javascript :: javasript document referrer 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =