2.6 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7daa367417b2b2512b6c | Об'єднання масиву у рядок з використанням методу Join | 1 | 18221 | combine-an-array-into-a-string-using-the-join-method |
--description--
Метод join
використовується для об'єднання елементів масиву для створення стрічки. Потрібний аргумент для розділювача, який використовується для відокремлення елементів масиву у рядку.
Наприклад:
const arr = ["Hello", "World"];
const str = arr.join(" ");
str
матиме значення рядка Hello World
.
--instructions--
Використовуйте метод join
(з-поміж інших) у функції sentensify
для створення речення зі слів у рядку str
. Ваша функція повинна повертати рядок. Наприклад, I-like-Star-Wars
буде перетворений в I like Star Wars
. Для цього завдання не використовуйте метод replace
.
--hints--
Використовуйте метод join
у вашому коді.
assert(code.match(/\.join/g));
Не використовуйте метод replace
у вашому коді.
assert(!code.match(/\.?[\s\S]*?replace/g));
sentensify("May-the-force-be-with-you")
повинен повертати рядок.
assert(typeof sentensify('May-the-force-be-with-you') === 'string');
sentensify("May-the-force-be-with-you")
повинен повертати рядок May the force be with you
.
assert(sentensify('May-the-force-be-with-you') === 'May the force be with you');
sentensify("The.force.is.strong.with.this.one")
повинен повертати рядок The force is strong with this one
.
assert(
sentensify('The.force.is.strong.with.this.one') ===
'The force is strong with this one'
);
sentensify("There,has,been,an,awakening")
повинен повертати рядок There has been an awakening
.
assert(
sentensify('There,has,been,an,awakening') === 'There has been an awakening'
);
--seed--
--seed-contents--
function sentensify(str) {
// Only change code below this line
// Only change code above this line
}
sentensify("May-the-force-be-with-you");
--solutions--
function sentensify(str) {
return str.split(/\W/).join(' ');
}