Last active
October 11, 2021 13:23
-
-
Save mrwithersea/267600718c627ab936001078e3a2a808 to your computer and use it in GitHub Desktop.
Ramda Title Case
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
import R from 'ramda'; | |
const capitalize = | |
R.converge( | |
R.concat, | |
[ | |
R.compose( | |
R.toUpper, | |
R.head | |
), | |
R.tail, | |
] | |
); | |
const toTitleCase = | |
R.compose( | |
R.join(' '), | |
R.map(capitalize), | |
R.split(' ') | |
); |
const R = require('ramda')
const capitalize =
R.converge(
R.concat(), [
R.compose(
R.toUpper,
R.head
),
R.tail,
]
);
const titleCase =
R.compose(
R.join(' '),
R.map(capitalize),
R.split(' '),
R.toLower,
);
console.log('typeof titleCase:', typeof(titleCase))
console.log(titleCase('how do you like this?'))
console.log(titleCase('RAMDA FUNCTIONS RETURN FUNCTIONS.'))
// Results
// typeof titleCase: function
// How Do You Like This?
// Ramda Functions Return Functions.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great! I'd suggest removing parentheses in
R.concat()
part, as they are not needed here, and it looks like function runs w/o arguments.