2.6 KiB
2.6 KiB
id, title, isRequired, challengeType, videoUrl, localeTitle
id | title | isRequired | challengeType | videoUrl | localeTitle |
---|---|---|---|---|---|
ac6993d51946422351508a41 | Truncate a String | true | 5 | 截断字符串 |
Description
...
结尾的截断字符串。如果卡住,请记得使用Read-Search-Ask 。编写自己的代码。 Instructions
Tests
tests:
- text: '<code>truncateString("A-tisket a-tasket A green and yellow basket", 8)</code>应该返回“A-tisket ......”。'
testString: assert(truncateString("A-tisket a-tasket A green and yellow basket", 8) === "A-tisket...");
- text: '<code>truncateString("Peter Piper picked a peck of pickled peppers", 11)</code>应该回归“Peter Piper ......”。'
testString: assert(truncateString("Peter Piper picked a peck of pickled peppers", 11) === "Peter Piper...");
- text: '<code>truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length)</code>应该返回“A-tisket a-tasket A green and yellow basket”。'
testString: assert(truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length) === "A-tisket a-tasket A green and yellow basket");
- text: '<code>truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2)</code>应返回“A-tisket a-tasket A green and yellow basket”。'
testString: assert(truncateString('A-tisket a-tasket A green and yellow basket', 'A-tisket a-tasket A green and yellow basket'.length + 2) === 'A-tisket a-tasket A green and yellow basket');
- text: '<code>truncateString("A-", 1)</code>应返回“A ...”。'
testString: assert(truncateString("A-", 1) === "A...");
- text: '<code>truncateString("Absolutely Longer", 2)</code>应返回“Ab ...”。'
testString: assert(truncateString("Absolutely Longer", 2) === "Ab...");
Challenge Seed
function truncateString(str, num) {
// Clear out that junk in your trunk
return str;
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
Solution
// solution required