Skip to content

Instantly share code, notes, and snippets.

@jdmorlan
Last active August 28, 2016 23:51
Show Gist options
  • Save jdmorlan/180b8f316773d7f418bfee9bc618426c to your computer and use it in GitHub Desktop.
Save jdmorlan/180b8f316773d7f418bfee9bc618426c to your computer and use it in GitHub Desktop.
const compose = (...funcs) => {
if (funcs.length === 0) {
return (arg) => arg
}
if (funcs.length === 1) {
return funcs[0]
}
}
// No funcs passed
const composedFunction = compose()
composedFunction === (arg) => arg === function composedFunction (arg) { return arg }
composedFunction(1) //=> echos the argument, so the result would be 1
// One func passed
const composedFunction = compose((x) => x + 2)
composedFunction === (x) => x + 2 === function composedFunction (x) { return x + 2 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment