curriculum/challenges/english/blocks/lab-spinal-case-converter/a103376db3ba46b2d50db289.md
Spinal case is a string format where all words are in lowercase and separated by hyphens. "this-is-spinal-tap" is an example of a string in spinal case.
In this lab, you will create a function that converts a given string to spinal case.
Objective: Fulfill the user stories below and get all the tests to pass to complete the lab.
User Stories:
spinalCase.spinalCase function should take a single argument, a string.spinalCase function should return the string in spinal case format. For example, if the argument is ProductLanding page, the function should return product-landing-page.You should create a function named spinalCase.
assert.isFunction(spinalCase);
spinalCase should take a single argument.
assert.lengthOf(spinalCase, 1);
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');
function spinalCase(str) {
str = str.replace(/([a-z](?=[A-Z]))/g, '$1 ');
return str.toLowerCase().replace(/\ |\_/g, '-');
}