Skip to content

Instantly share code, notes, and snippets.

@mrwithersea
Last active October 11, 2021 13:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrwithersea/267600718c627ab936001078e3a2a808 to your computer and use it in GitHub Desktop.
Save mrwithersea/267600718c627ab936001078e3a2a808 to your computer and use it in GitHub Desktop.
Ramda Title Case
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(' ')
);
@pufflik
Copy link

pufflik commented Feb 5, 2020

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.

@vijaypatil
Copy link

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