Kebab Case to Pascal Case (v2)

Revision 2 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
for loop
  const kebab = 'feaTure-name-VerY-long'
  if (!kebab) {
    return kebab;
  }
  const pieces = kebab.split('-');
  let formattedString = '';
  for (const piece of pieces) {
    if (piece.length > 0) {
      formattedString += piece[0].toUpperCase();
    }
    if (piece.length > 1) {
      formattedString += piece.slice(1).toLowerCase();
    }
  }
ready
map and join
  const kebab = 'feaTure-name-VerY-long'
  if (!kebab) {
    return kebab;
  }
  const pieces = kebab.split('-').filter(piece => piece.length > 0);
  return pieces
    .map(piece => {
      const chars = piece.split('');
      return chars.map((ch, index) => (index === 0 ? ch.toUpperCase() : ch.toLowerCase())).join('');
    })
    .join('');
ready
for loop - string parts
  const kebab = 'feaTure-name-VerY-long'
  if (!kebab) {
    return kebab;
  }
  const pieces = kebab.split('-');
  const stringParts = []
  for (const piece of pieces) {
    if (piece.length > 0) {
      stringParts.push(piece[0].toUpperCase());
    }
    if (piece.length > 1) {
   
   stringParts.push(piece.slice(1).toLowerCase());
    }
  }
  stringParts.join('');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.