2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: a103376db3ba46b2d50db289
|
2020-12-16 00:37:30 -07:00
|
|
|
title: 短线连接格式
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 5
|
2020-09-07 16:10:29 +08:00
|
|
|
forumTopicId: 16078
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
在这道题目中,我们需要写一个函数,把一个字符串转换为“短线连接格式”。短线连接格式的意思是,所有字母都是小写,且用`-`连接。比如,对于`Hello World`,应该转换为`hello-world`;对于`I love_Javascript-VeryMuch`,应该转换为`i-love-javascript-very-much`。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
如果你遇到了问题,请点击[帮助](https://forum.freecodecamp.one/t/topic/157)。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`spinalCase('This Is Spinal Tap')`应该返回`'this-is-spinal-tap'`。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert.deepEqual(spinalCase('This Is Spinal Tap'), 'this-is-spinal-tap');
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`spinalCase('thisIsSpinalTap')`应该返回`'this-is-spinal-tap'`。
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert.strictEqual(spinalCase('thisIsSpinalTap'), 'this-is-spinal-tap');
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`spinalCase('The_Andy_Griffith_Show')`应该返回`'the-andy-griffith-show'`。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert.strictEqual(
|
|
|
|
spinalCase('The_Andy_Griffith_Show'),
|
|
|
|
'the-andy-griffith-show'
|
|
|
|
);
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`spinalCase('Teletubbies say Eh-oh')`应该返回`'teletubbies-say-eh-oh'`。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert.strictEqual(
|
|
|
|
spinalCase('Teletubbies say Eh-oh'),
|
|
|
|
'teletubbies-say-eh-oh'
|
|
|
|
);
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`spinalCase('AllThe-small Things')`应该返回`'all-the-small-things'`。
|
2020-09-07 16:10:29 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert.strictEqual(spinalCase('AllThe-small Things'), 'all-the-small-things');
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|