* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
2.7 KiB
2.7 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7daa367417b2b2512b6b | Split a String into an Array Using the split Method | 1 | 使用split方法将字符串拆分为数组 |
Description
split
方法将字符串拆分为字符串数组。它接受分隔符的参数,分隔符可以是用于分解字符串或正则表达式的字符。例如,如果分隔符是空格,则会得到一个单词数组,如果分隔符是空字符串,则会得到字符串中每个字符的数组。下面是两个用空格分隔一个字符串的例子,然后用正则表达式用数字分割另一个字符串: var str =“Hello World”;由于字符串是不可变的,因此
var bySpace = str.split(“”);
//将bySpace设置为[“Hello”,“World”]
var otherString =“How9are7you2today”;
var byDigits = otherString.split(/ \ d /);
//将byDigits设置为[“How”,“are”,“you”,“today”]
split
方法可以更轻松地使用它们。 Instructions
splitify
函数内的split
方法将str
拆分为单词数组。该函数应该返回数组。请注意,单词并不总是用空格分隔,并且数组不应包含标点符号。 Tests
tests:
- text: 您的代码应该使用<code>split</code>方法。
testString: assert(code.match(/\.split/g));
- text: '<code>splitify("Hello World,I-am code")</code>应返回<code>["Hello", "World", "I", "am", "code"]</code> 。'
testString: assert(JSON.stringify(splitify("Hello World,I-am code")) === JSON.stringify(["Hello", "World", "I", "am", "code"]));
- text: '<code>splitify("Earth-is-our home")</code>应该返回<code>["Earth", "is", "our", "home"]</code> 。'
testString: assert(JSON.stringify(splitify("Earth-is-our home")) === JSON.stringify(["Earth", "is", "our", "home"]));
- text: '<code>splitify("This.is.a-sentence")</code>应该返回<code>["This", "is", "a", "sentence"]</code> 。'
testString: assert(JSON.stringify(splitify("This.is.a-sentence")) === JSON.stringify(["This", "is", "a", "sentence"]));
Challenge Seed
function splitify(str) {
// Add your code below this line
// Add your code above this line
}
splitify("Hello World,I-am code");
Solution
// solution required