Intermediate Algorithm Scripting: Spinal Tap Case

just confused with this solution am getting all passed except for one the question is
Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
and my code is

function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
  return str.split(/(?=[A-Z])/g).join("-").replace(/[" "_]/g,"").toLowerCase();

the error i get at freecode camp is when
str= "Teletubbies say Eh-oh";
output is =teletubbiessay-eh-oh
but frecodecamp say it must be ="teletubbies-say-eh-oh"
i used if the first letter is capttal letter thet where i split;
any ides

you don’t need to split only if the letter is upper case, what you need to do is change all spaces to dashes
“bLuE ElEpHaNT iS eATiNg BANanaS” should become “blue-elephant-is-eating-bananas”

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


1 Like

how about when the given is "thisIsSpinalTap"
No dashe no space

there your code works, and you are right that there is nothing like my example in the tests.
a word

  • is preceded with a space
  • start with a capital letter
  • or both

you are missing recognising the words that don’t start with a capital letter

1 Like

Thank you new ways new solutions…i just don know how i solved it done after hours on my own way Thank you bro

return  str.replace(/[-]/g," ").split(/(?=[A-Z" "_-])/g).map(x=>x.trim()).filter((x)=>{if(x!=" "&&x!="_"&&x!="-"&&x!=""){return x}}).join("-").toLowerCase();