Intermediate Algorithm Scripting - Spinal Tap Case

Tell us what’s happening:
Describe your issue in detail here.
My code passed all the user tests except for one can any one tell me what i did wrong

/ /running tests
spinalCase(“The_Andy_Griffith_Show”) should return the string the-andy-griffith-show.
// tests completed
// console output
this-is-spinal-tap
this-is-spinal-tap
all-the-small-things
the--andy--griffith-_-show

Your code so far

function spinalCase(str) {
  let string = str.split(""),
      newStr  = "",
      marks = /\W/

  for (let i=0; i<string.length; i++) {
    
    if (string[i] === string[i].toUpperCase() && string.indexOf(string[i]) > 0) {

      if (string[i] !== " " && !marks.test(string[i])) {
        string[i] = " "+string[i]
      }
    }

    if (string[i]) {
      newStr += string[i]
    }
  }

  return newStr.split(/\s+/).join("-").toLowerCase();
}

console.log(spinalCase('This Is Spinal Tap'));

console.log(spinalCase("thisIsSpinalTap"))

console.log(spinalCase("AllThe-small Things"))

console.log(spinalCase("The_Andy_Griffith_Show"))

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 11; Nokia 3.4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Mobile Safari/537.36

Challenge: Intermediate Algorithm Scripting - Spinal Tap Case

Link to the challenge:

you can try first by looking into how to tackle this “The_Andy_Griffith_Show” first along with with your “s+” split

once you have that try looking into how to do this for “camelCase” string using regex

once you have that then you can combine those in a single regex to solve this step

happy coding :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.