Skip to content

Instantly share code, notes, and snippets.

@Goloburda
Created November 28, 2019 14:27
Show Gist options
  • Save Goloburda/c7b4c369205b042820747a5e440e8413 to your computer and use it in GitHub Desktop.
Save Goloburda/c7b4c369205b042820747a5e440e8413 to your computer and use it in GitHub Desktop.
Allow to apply number of functions to passed argument.
const fn1 = arg => arg.toUpperCase();
const fn2 = arg =>
arg
.split("")
.reverse()
.join("");
const fn3 = arg => arg + "WoW";
const fn4 = arg => arg.split("");
const pipe = (...rest) => name => rest.reduce((acc, cur) => cur(acc), name);
const res = pipe(
fn1,
fn2,
fn3,
fn4
)("Mikita");
console.log(res); // ["A", "T", "I", "K", "I", "M", "W", "o", "W"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment