Created
March 9, 2018 19:44
-
-
Save AkimaLunar/b2316c8097df7cf6954225807e2827b9 to your computer and use it in GitHub Desktop.
Compose takes in functions as arguments and returns a single function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const compose = (...fns) => // 1. the spread operator torns function arguments into an array fns | |
(arg) => // 2. a function is then returned that expects one argument arg | |
fns.reduce( // 3. Reducing the fins with arg as the initial value | |
(composed, f) => f(composed), // 4. Each function is called with the result of the previous functions | |
arg // 3.arg is the initial value | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment