Implement a Spinal Case Converter - Implement a Spinal Case Converter

Tell us what’s happening:

I’m having trouble making sense of the criteria for converting to spinal case. From the instructions I assumed all that would be needed was to replace spaces with hyphens, but see that there are many criteria needed for the tests. While I could for example replace all capital letters (after the 1st) and special characters to pass the specific tests, I would be coding to the few tests, and then ignoring the instructions.

Specifically, JavaScript should simply be made lower case but thisIsSpinalTap needs to be hyphenated at before each capital letter in order to pass the tests.

I’m not aware of a means to use RegExp to detect words in the dictionary for example to help pass the tests, so am curious if there’s some advice that can be given to build out the conceptual logic that can then be made into code.

Your code so far

const spinalCase = sentence => {
  return sentence.replace(/\s+/g,'-').toLowerCase();
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Implement a Spinal Case Converter - Implement a Spinal Case Converter

Hi @keebler

image

For test 5 you need to swap the underscores for hyphens.

For the uppercase letters, you could find a way to test for uppercase letters.

Happy coding

Thanks - i’m confused though about the logic that needs to be implemented, not the way to code itself, specifically the part with capitals.

User Story 3 says JavaScript is awesome should return javascript-is-awesome. While I know I can insert a hyphen before each capital letter that follows a lowercase letter, this would mean the user story wouldn’t work unless I’m missing something about the pattern that needs to be created in the regex.

Yeah user story 3 looks wrong, well that example at least.

Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

created an issue here