Oliver Eyton-Williams 0bd52f8bd1
Feat: add new Markdown parser (#39800)
and change all the challenges to new `md` format.
2020-11-27 10:02:05 -08:00

1.3 KiB

id, title, challengeType, forumTopicId
id title challengeType forumTopicId
a103376db3ba46b2d50db289 Spinal Tap Case 5 16078

--description--

Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.

--hints--

spinalCase("This Is Spinal Tap") should return "this-is-spinal-tap".

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

spinalCase("thisIsSpinalTap") should return "this-is-spinal-tap".

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

spinalCase("The_Andy_Griffith_Show") should return "the-andy-griffith-show".

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

spinalCase("Teletubbies say Eh-oh") should return "teletubbies-say-eh-oh".

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

spinalCase("AllThe-small Things") should return "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, '-');
}