Created
November 15, 2017 07:35
-
-
Save zhjgithub/a2b3e32813571b2e896f73f134ed4ba1 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
const compose = (...fns) => data => | |
fns.reduceRight((value, fn) => fn(value), data) | |
const trim = str => str.trim() | |
const split = separator => str => str.split(separator) | |
const notEmpty = str => str.length > 0 | |
const removeEmpty = parts => parts.filter(notEmpty) | |
const words = compose(removeEmpty, split(' '), trim) | |
const upperCapital = str => str.charAt(0).toUpperCase() + str.substr(1) | |
const capitalize = filtered => filtered.map(upperCapital) | |
const join = separator => arr => arr.join(separator) | |
const titleCase = compose(join(' '), capitalize, words) | |
titleCase('this is a test') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment