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
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: spinal-tap-case
|
2018-10-04 14:37:37 +01:00
|
|
|
---
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --description--
|
|
|
|
|
2018-10-04 14:37:37 +01:00
|
|
|
Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --hints--
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`spinalCase("This Is Spinal Tap")` should return `"this-is-spinal-tap"`.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert.deepEqual(spinalCase('This Is Spinal Tap'), 'this-is-spinal-tap');
|
|
|
|
```
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`spinalCase("thisIsSpinalTap")` should return `"this-is-spinal-tap"`.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert.strictEqual(spinalCase('thisIsSpinalTap'), 'this-is-spinal-tap');
|
2018-10-04 14:37:37 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`spinalCase("The_Andy_Griffith_Show")` should return `"the-andy-griffith-show"`.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert.strictEqual(
|
|
|
|
spinalCase('The_Andy_Griffith_Show'),
|
|
|
|
'the-andy-griffith-show'
|
|
|
|
);
|
|
|
|
```
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`spinalCase("Teletubbies say Eh-oh")` should return `"teletubbies-say-eh-oh"`.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
|
|
|
```js
|
2020-11-27 19:02:05 +01:00
|
|
|
assert.strictEqual(
|
|
|
|
spinalCase('Teletubbies say Eh-oh'),
|
|
|
|
'teletubbies-say-eh-oh'
|
|
|
|
);
|
2018-10-04 14:37:37 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`spinalCase("AllThe-small Things")` should return `"all-the-small-things"`.
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert.strictEqual(spinalCase('AllThe-small Things'), 'all-the-small-things');
|
|
|
|
```
|
|
|
|
|
|
|
|
# --seed--
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
## --seed-contents--
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
function spinalCase(str) {
|
|
|
|
return str;
|
|
|
|
}
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
spinalCase('This Is Spinal Tap');
|
|
|
|
```
|
2018-10-04 14:37:37 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --solutions--
|
2018-10-04 14:37:37 +01:00
|
|
|
|
|
|
|
```js
|
|
|
|
function spinalCase(str) {
|
|
|
|
str = str.replace(/([a-z](?=[A-Z]))/g, '$1 ');
|
|
|
|
return str.toLowerCase().replace(/\ |\_/g, '-');
|
|
|
|
}
|
|
|
|
```
|