* fix(curriculum): tests quotes * fix(curriculum): fill seed-teardown * fix(curriculum): fix tests and remove unneeded seed-teardown
2.2 KiB
2.2 KiB
id, title, isRequired, challengeType
id | title | isRequired | challengeType |
---|---|---|---|
ab6137d4e35944e21037b769 | Title Case a Sentence | true | 5 |
Description
Instructions
Tests
tests:
- text: <code>titleCase("I'm a little tea pot")</code> should return a string.
testString: assert(typeof titleCase("I'm a little tea pot") === "string", '<code>titleCase("I'm a little tea pot")</code> should return a string.');
- text: <code>titleCase("I'm a little tea pot")</code> should return <code>I'm A Little Tea Pot</code>.
testString: assert(titleCase("I'm a little tea pot") === "I'm A Little Tea Pot", '<code>titleCase("I'm a little tea pot")</code> should return <code>I'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");