Skip to content

Instantly share code, notes, and snippets.

@titouancreach
Last active March 27, 2018 12:30
Show Gist options
  • Save titouancreach/76424348c0afe90dc3ddbd76e7cacf3d to your computer and use it in GitHub Desktop.
Save titouancreach/76424348c0afe90dc3ddbd76e7cacf3d to your computer and use it in GitHub Desktop.
compose function written in recursive
export function compose(...fns) {
if (fns.length === 0) {
return fns;
}
return value => {
const g = fnsAcc => {
if (fnsAcc.length === 1) {
return fnsAcc[0](value);
}
const [head, ...tail] = fnsAcc;
return head(g(tail))
};
return g(fns)
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment