Created
January 13, 2021 11:31
-
-
Save kucherenko/136c376a7e662b125b703e951cf7e170 to your computer and use it in GitHub Desktop.
This file contains 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
// Compose functions from right to left | |
const compose = (...fns) => x => fns.reduceRight((y, f) => f(y), x); | |
// Example | |
const lowercase = str => str.toLowerCase(); | |
const capitalize = str => `${str.charAt(0).toUpperCase()}${str.slice(1)}`; | |
const reverse = str => str.split('').reverse().join(''); | |
const fn = compose(reverse, capitalize, lowercase); | |
// We will execute `lowercase`, `capitalize` and `reverse` in order | |
fn('Hello World') === 'dlrow olleH'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment