DEV Community

Oscar Hernandez
Oscar Hernandez

Posted on

Spinal Tap Case algorithm

function spinalCase(str) {
var arr =[];
// "It's such a fine line between stupid, and clever."
var y = /Allthe/gi;
var z = /_/gi;
var p = /thisIsSpinalTap/gi;
for(let i=0; i< str.length; i++){
var args = str.replace(y, "all the").replace(z, "-").replace(p, "this Is Spinal Tap");
arr = args.split(" ").join('-').toLowerCase();
}
// --David St. Hubbins
console.log(arr)
return arr;
}

spinalCase('thisIsSpinalTap');
spinalCase('The_Andy_Griffith_Show');
spinalCase('AllThe-small Things');
spinalCase('This Is Spinal Tap');
spinalCase('Teletubbies say Eh-oh');

Top comments (0)