Javascript Currying

Transform a function with multiple parameters into calling a nesting function multiple times with one parameter; the functionality of the two situations is not changed.

For example, the following functions have the same functionality but different formats:

// original format
function add(a, b) {
  return a + b;
}

// currying format
function curryingAddFirst(a) {
  return function (b) {
    return a + b;
  };
}

// currying format with arrow function
const curryingAddSecond = (a) => (b) => a + b;

Comments

Popular posts from this blog

WSL2配置proxychains, 使得终端走宿主机代理

Node.js & Express.js - A Refresher

What is MERN?