Spinal Tap Case- testcase failed

Spinal Tap Case- testcase failed
0
#1

Tell us what’s happening:

Your code so far


function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
  let caps = str.match(/^\w|[A-Z]/g);
  let temp = str.split(/^\w|[A-Z]/g);
  temp.splice(0,1);
  console.log(temp);
  for(let i=0; i<caps.length; i++){
    temp[i] = caps[i].toLowerCase() + temp[i];
  }
  let output = [];
  for(let i in temp){
    let x = temp[i].match(/[a-z]/g);
    output.push(x.join(''));
  }
  str = output.join('-');
  return str;
}

console.log(spinalCase('AllThe-small Things')); 

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/spinal-tap-case

I fail this testcase. Can someone help me please ?

0 Likes

#2

You are getting all-thesmall-things; you are removing the dash without putting it back (or just not remove it I imagine)

You have the same issue with spinalCase("Teletubbies say Eh-oh")

This part here remove the dash: (try to console.log() all your variables and you will see for yourself were the issue is):

let output = [];
  for(let i in temp){
    let x = temp[i].match(/[a-z]/g);
    output.push(x.join(''));
  }
0 Likes

#3

Thanks @leahleen. Any ideas abt how to resolve this issue ?

0 Likes

#4

You can try using https://regex101.com to check what match(/[a-z]/g) actually match, and see if you can find a way to change things a little (temp is ["all", "the-small ", "things"], which you can get writing console.log(temp) before the loop, so I suggest trying with the three strings to see what the regex match)

0 Likes

#5

thanks @leahleen for the suggestion. And sorry for late reply as I was out.

0 Likes