Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.6 KiB
Raw Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
a103376db3ba46b2d50db289 短线连接格式 5 16078 spinal-tap-case

--description--

在这道题目中,我们需要写一个函数,把一个字符串转换为“短线连接格式”。短线连接格式的意思是,所有字母都是小写,且用 - 连接。比如,Hello World 的短线连接格式为 hello-worldI love_Javascript-VeryMuch 的短线连接格式为 i-love-javascript-very-much

--hints--

spinalCase("This Is Spinal Tap") 应返回 "this-is-spinal-tap"

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

spinalCase("thisIsSpinalTap") 应返回 "this-is-spinal-tap"

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

spinalCase("The_Andy_Griffith_Show") 应返回 "the-andy-griffith-show"

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

spinalCase("Teletubbies say Eh-oh") 应返回 "teletubbies-say-eh-oh"

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

spinalCase("AllThe-small Things") 应返回 "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, '-');
}