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
boo-who.english.md
chunky-monkey.english.md
confirm-the-ending.english.md
convert-celsius-to-fahrenheit.english.md
factorialize-a-number.english.md
falsy-bouncer.english.md
find-the-longest-word-in-a-string.english.md
finders-keepers.english.md
mutations.english.md
repeat-a-string-repeat-a-string.english.md
return-largest-numbers-in-arrays.english.md
reverse-a-string.english.md
slice-and-splice.english.md
title-case-a-sentence.english.md
truncate-a-string.english.md
where-do-i-belong.english.md
basic-data-structures
basic-javascript
debugging
es6
functional-programming
intermediate-algorithm-scripting
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
formattingConversion
math-challenges
requiresTests
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
guide
mock-guide
tools
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.tests
LICENSE.md
README.french.md
README.italian.md
README.md
change_volumes_owner.sh
docker-compose-shared.yml
docker-compose.tests.yml
docker-compose.yml
lerna.json
netlify.toml
package-lock.json
package.json
sample.env
Valeriy 79d9012432 fix(curriculum): quotes in tests ()
* fix(curriculum): tests quotes

* fix(curriculum): fill seed-teardown

* fix(curriculum): fix tests and remove unneeded seed-teardown
2018-10-20 23:32:47 +05:30

2.2 KiB

id, title, isRequired, challengeType
id title isRequired challengeType
ab6137d4e35944e21037b769 Title Case a Sentence true 5

Description

Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case. For the purpose of this exercise, you should also capitalize connecting words like "the" and "of". Remember to use Read-Search-Ask if you get stuck. Write your own code.

Instructions

Tests

tests:
  - text: <code>titleCase("I&#39;m a little tea pot")</code> should return a string.
    testString: assert(typeof titleCase("I'm a little tea pot") === "string", '<code>titleCase("I&#39;m a little tea pot")</code> should return a string.');
  - text: <code>titleCase("I&#39;m a little tea pot")</code> should return <code>I&#39;m A Little Tea Pot</code>.
    testString: assert(titleCase("I'm a little tea pot") === "I'm A Little Tea Pot", '<code>titleCase("I&#39;m a little tea pot")</code> should return <code>I&#39;m A Little Tea Pot</code>.');
  - text: <code>titleCase("sHoRt AnD sToUt")</code> should return <code>Short And Stout</code>.
    testString: assert(titleCase("sHoRt AnD sToUt") === "Short And Stout", '<code>titleCase("sHoRt AnD sToUt")</code> should return <code>Short And Stout</code>.');
  - text: <code>titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")</code> should return <code>Here Is My Handle Here Is My Spout</code>.
    testString: assert(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") === "Here Is My Handle Here Is My Spout", '<code>titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")</code> should return <code>Here Is My Handle Here Is My Spout</code>.');

Challenge Seed

function titleCase(str) {
  return str;
}

titleCase("I'm a little tea pot");

Solution

function titleCase(str) {
  return str.split(' ').map(word => word.charAt(0).toUpperCase() + word.substring(1).toLowerCase()).join(' ');
}

titleCase("I'm a little tea pot");