Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
split function is not working with the regex provided

this is my take on the problem. i have successfully passed 3/4. the only thing messing up my solution is that extra white space after ‘telebubbles’. how do i progress further? i’m not good with replace.

function spinalCase(str) {
let k=str.split(/[\s-_]?(?=[A-Z])/g).join('-').toLowerCase()
console.log(k)
return k
}

spinalCase('This Is Spinal Tap');//passed
spinalCase("thisIsSpinalTap")//passed
spinalCase("The_Andy_Griffith_Show")//passed
spinalCase("Teletubbies say Eh-oh")//not working
spinalCase("AllThe-small Things")//passed

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You may use this regex to fix your problem:

/\s+|[-_]*(?=[A-Z])/

Code:

function spinalCase(str) {
    let k = str.split(/\s+|[-_]*(?=[A-Z])/g).join('-').toLowerCase();
    console.log(k);
    return k;
}

spinalCase('This Is Spinal Tap'); //passed
spinalCase("thisIsSpinalTap"); //passed
spinalCase("The_Andy_Griffith_Show"); //passed
spinalCase("Teletubbies say Eh-oh"); //passed
spinalCase("AllThe-small Things"); //passed

RegEx Details:

  • \s+: Match 1+ whitespaces
  • |: OR
  • [-_]*(?=[A-Z]): Match 0 or more of underscore or hyphen if that followed by an uppercase letter
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda