Created
April 12, 2020 17:09
-
-
Save larizzatg/a0df00bd8705c47626f431b7994cf848 to your computer and use it in GitHub Desktop.
learning how to do a basic compose
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) => { | |
let result = null; | |
return (...args) => { | |
result = args; | |
for(let i = fns.length - 1; i >= 0; i--) { | |
let fnResult = fns[i](...result); | |
result = Array.isArray(fnResult) ? fnResult : [fnResult]; | |
} | |
return result; | |
}; | |
}; | |
const consider = name => `I think it could be... ${name}`; | |
const exclaim = statement => `${statement.toUpperCase()}!`; | |
const blame = _.compose(consider, exclaim); | |
const result = blame('you'); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment