Skip to main content

--description--

Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.

--hints--

spinalCase("This Is Spinal Tap") should return the string this-is-spinal-tap.

assert.deepEqual(spinalCase('This Is Spinal Tap'), 'this-is-spinal-tap');

spinalCase("thisIsSpinalTap") should return the string this-is-spinal-tap.

assert.strictEqual(spinalCase('thisIsSpinalTap'), 'this-is-spinal-tap');

spinalCase("The_Andy_Griffith_Show") should return the string the-andy-griffith-show.

assert.strictEqual(
spinalCase('The_Andy_Griffith_Show'),
'the-andy-griffith-show'
);

spinalCase("Teletubbies say Eh-oh") should return the string teletubbies-say-eh-oh.

assert.strictEqual(
spinalCase('Teletubbies say Eh-oh'),
'teletubbies-say-eh-oh'
);

spinalCase("AllThe-small Things") should return the string all-the-small-things.

assert.strictEqual(spinalCase('AllThe-small Things'), 'all-the-small-things');

--seed--

--seed-contents--

function spinalCase(str) {
return str;
}

spinalCase('This Is Spinal Tap');

--solutions--

function spinalCase(str) {
str = str.replace(/([a-z](?=[A-Z]))/g, '$1 ');
return str.toLowerCase().replace(/\ |\_/g, '-');
}