Tell us what’s happening:
I made a function to solve the algorithm case:
“Intermediate Algorithm Scripting: Spinal Tap Case”
And I expect it to pass since it outputs:
the-andy-griffith-show
But I keep getting the error:
spinalCase("TheAndyGriffith_Show")
should return
"the-andy-griffith-show"
Your code so far
function spinalCase(str) {
let intermediate = str.replace(/([A-Z])/g, " $1");
intermediate = intermediate.replace(/[_-]/, " ");
let wordArray = intermediate.split(" ");
let cleanedArray = [];
wordArray.forEach(function(item) {
if(item !== "") {
cleanedArray.push(item);
}
});
let result = cleanedArray.join("-");
result = result.toLowerCase();
result = result.trim();
return result;
}
spinalCase('TheAndyGriffith_Show');
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0
.
Challenge: Spinal Tap Case
Link to the challenge: