Use the split method inside the splitify function to split str into an array of words. The function should return the array. Note that the words are not always separated by spaces, and the array should not contain punctuation.
使用 splitify 函数中的 split 方法将 str 拆分为单词数组。 该函数应返回数组。 请注意,单词并不总是用空格分隔,并且数组不应包含标点符号。
function splitify(str) {
// Only change code below this line
var pattern = /[\s,-.]/gi;
var strarr = str.split(pattern);
console.log(strarr);
return strarr;
// Only change code above this line
}
splitify("Hello World,I-am code");
Comments
Post a Comment