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 ?


#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(''));
  }

#3

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