2018-10-04 14:37:37 +01:00
|
|
|
---
|
|
|
|
id: a103376db3ba46b2d50db289
|
|
|
|
title: Spinal Tap Case
|
|
|
|
challengeType: 5
|
2019-07-31 11:32:23 -07:00
|
|
|
forumTopicId: 16078
|
2018-10-04 14:37:37 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
|
|
|
<section id='description'>
|
|
|
|
Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Instructions
|
|
|
|
<section id='instructions'>
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
|
|
|
- text: <code>spinalCase("This Is Spinal Tap")</code> should return <code>"this-is-spinal-tap"</code>.
|
2019-07-24 01:56:38 -07:00
|
|
|
testString: assert.deepEqual(spinalCase("This Is Spinal Tap"), "this-is-spinal-tap");
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: <code>spinalCase("thisIsSpinal<wbr>Tap")</code> should return <code>"this-is-spinal-tap"</code>.
|
2019-07-24 01:56:38 -07:00
|
|
|
testString: assert.strictEqual(spinalCase('thisIsSpinalTap'), "this-is-spinal-tap");
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: <code>spinalCase("The_Andy_<wbr>Griffith_Show")</code> should return <code>"the-andy-griffith-show"</code>.
|
2019-07-24 01:56:38 -07:00
|
|
|
testString: assert.strictEqual(spinalCase("The_Andy_Griffith_Show"), "the-andy-griffith-show");
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: <code>spinalCase("Teletubbies say Eh-oh")</code> should return <code>"teletubbies-say-eh-oh"</code>.
|
2019-07-24 01:56:38 -07:00
|
|
|
testString: assert.strictEqual(spinalCase("Teletubbies say Eh-oh"), "teletubbies-say-eh-oh");
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: <code>spinalCase("AllThe-small Things")</code> should return <code>"all-the-small-things"</code>.
|
2019-07-24 01:56:38 -07:00
|
|
|
testString: assert.strictEqual(spinalCase("AllThe-small Things"), "all-the-small-things");
|
2018-10-04 14:37:37 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
function spinalCase(str) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
spinalCase('This Is Spinal Tap');
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
function spinalCase(str) {
|
|
|
|
str = str.replace(/([a-z](?=[A-Z]))/g, '$1 ');
|
|
|
|
return str.toLowerCase().replace(/\ |\_/g, '-');
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|