Files
.github
api-server
client
config
curriculum
challenges
_meta
arabic
chinese
english
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
debugging
es6
functional-programming
intermediate-algorithm-scripting
arguments-optional.english.md
binary-agents.english.md
convert-html-entities.english.md
diff-two-arrays.english.md
dna-pairing.english.md
drop-it.english.md
everything-be-true.english.md
make-a-person.english.md
map-the-debris.english.md
missing-letters.english.md
pig-latin.english.md
search-and-replace.english.md
seek-and-destroy.english.md
smallest-common-multiple.english.md
sorted-union.english.md
spinal-tap-case.english.md
steamroller.english.md
sum-all-numbers-in-a-range.english.md
sum-all-odd-fibonacci-numbers.english.md
sum-all-primes.english.md
wherefore-art-thou.english.md
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
03-front-end-libraries
04-data-visualization
05-apis-and-microservices
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
portuguese
russian
spanish
schema
test
.babelrc
.editorconfig
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.md
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.js
gulpfile.js
index.js
lib.js
md-translation.js
package-entry.js
package-lock.json
package.json
utils.js
docs
search-indexing
tools
utils
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.gitpod.yml
.node-inspectorrc
.prettierignore
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.tests
LICENSE.md
README.md
SECURITY.md
change_volumes_owner.sh
docker-compose-shared.yml
docker-compose.tests.yml
docker-compose.yml
lerna.json
libcimp_index_js.patch
package-lock.json
package.json
patch_npm_and_install.sh
sample.env
Mo Zargham 437ba8b103 fix(curriculum): Read-search-ask link now point to correct url as noted in the issue ()
* fix: broken Read-search-ask link now point to correct url

* fix: changed link to original forum link with more views

* fix: changed http links to correct version

* fix: link in help modal
2019-11-19 19:54:48 -05:00

2.1 KiB

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

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, '-');
}