Files
freeCodeCamp/curriculum/challenges/ukrainian/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md
2023-03-28 21:16:03 +05:30

2.5 KiB
Raw Blame History

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(' ');
}