loading...

Spinal Tap Case algorithm

95freedom95 profile image Oscar Hernandez ・1 min read

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');

Discussion

markdown guide