Randell Dawson d78168f7db fix(curriculum): Remove unnecessary assert message argument from English challenges JavaScript Algorithms and Data Structures - 03 (#36403)
* fix: rm assert msg basic-data-structures

* fix: rm assert msg intermed-algo-scripting

* fix: rm assert msg data-structures projects
2019-07-24 10:56:38 +02:00

2.1 KiB

id, title, isRequired, challengeType
id title isRequired challengeType
a103376db3ba46b2d50db289 Spinal Tap Case true 5

Description

Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes. Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.

Instructions

Tests

tests:
  - text: <code>spinalCase("This Is Spinal Tap")</code> should return <code>"this-is-spinal-tap"</code>.
    testString: assert.deepEqual(spinalCase("This Is Spinal Tap"), "this-is-spinal-tap");
  - text: <code>spinalCase("thisIsSpinal<wbr>Tap")</code> should return <code>"this-is-spinal-tap"</code>.
    testString: assert.strictEqual(spinalCase('thisIsSpinalTap'), "this-is-spinal-tap");
  - text: <code>spinalCase("The_Andy_<wbr>Griffith_Show")</code> should return <code>"the-andy-griffith-show"</code>.
    testString: assert.strictEqual(spinalCase("The_Andy_Griffith_Show"), "the-andy-griffith-show");
  - text: <code>spinalCase("Teletubbies say Eh-oh")</code> should return <code>"teletubbies-say-eh-oh"</code>.
    testString: assert.strictEqual(spinalCase("Teletubbies say Eh-oh"), "teletubbies-say-eh-oh");
  - text: <code>spinalCase("AllThe-small Things")</code> should return <code>"all-the-small-things"</code>.
    testString: assert.strictEqual(spinalCase("AllThe-small Things"), "all-the-small-things");

Challenge Seed

function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
  return str;
}

spinalCase('This Is Spinal Tap');

Solution

function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
  str = str.replace(/([a-z](?=[A-Z]))/g, '$1 ');
  return str.toLowerCase().replace(/\ |\_/g, '-');
}